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

A tell is limited to 4,000 characters at the boundary, refused with a message naming the limit #14153

Merged opened this

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

Merged

scout/forge:scout/14139-a-tell-is-limited-to-4-000-characters-at → main 5 commits fork 5 threads · 5 unresolved

  • Merged. scout/14139-a-tell-is-limited-to-4-000-characters-at was merged into main as 8d60c45.

Review

Sign in to review this change.
25 files changed +227 −38
docs/features/share-tell.md +2 −2
@@ -5,7 +5,7 @@
55 told last already chosen (an app, or "the forge"), and nothing filed until you tap Send.
66
77 - Signed out: you are sent to sign in and back to the same draft.
8 - A share with nothing in it, a link that is not http(s), or more than 2,000 characters is
8 - A share with nothing in it, a link that is not http(s), or more than 4,000 characters is
99 refused with a sentence. Nothing is cut: a share too long is not kept, so no words vanish.
1010 - Send twice (double tap)? It tells once.
1111 - "Last told" is the newest of your issues in an app you can still write to and your
@@ -20,4 +20,4 @@ Code: `src/web/share_target.ts` (contract and refusal), `src/web/studio/share_te
2020
2121 ## A tell refused for length or emptiness (#13587)
2222
23 An empty tell, or one over 2,000 characters (`TELL_MAX`), answers 422 with the form again, the words still in the box and one sentence naming the limit; nothing is filed and a share token is not used up. The share sheet's `GET /tell` does the same. The terminal's share screen reads the same sentence from `refuseTell` (`src/web/share_target.ts`).
23 An empty tell, or one over 4,000 characters (`TELL_MAX`), answers 422 with the form again, the words still in the box and one sentence naming the limit; nothing is filed and a share token is not used up. The share sheet's `GET /tell` does the same. The terminal's share screen reads the same sentence from `refuseTell` (`src/web/share_target.ts`).
docs/mcp/tools/tell.md +1 −1
@@ -30,7 +30,7 @@ this tool all use:
3030 | error | words |
3131 | --- | --- |
3232 | `empty` | Say something first. |
33 | `body_too_long` | That is too long to tell in one go. |
33 | `body_too_long` | One thought, at most 4,000 characters. |
3434 | `unverified` | Verify your email first. |
3535 | `forbidden` | the crew's direction note |
3636 | anything else | That could not be told. |
src/actions/tell.ts +3 −3
@@ -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 } from "./tell_from.ts";
20 import { parseFrom, TELL_LIMIT_WORDS } from "./tell_from.ts";
2121 import { requireVerified } from "./verify.ts";
2222 import { VERIFY_FIRST } from "./verify_words.ts";
2323
@@ -162,8 +162,8 @@ export async function tell(
162162 /** What every door says when a tell is refused for an unverified address. */
163163 export const UNVERIFIED_WORDS = VERIFY_FIRST;
164164
165 /** What both doors say when `tell` refuses a text over `MAX_BODY`. */
166 export const TOO_LONG_WORDS = "That is too long to tell in one go.";
165 /** What both doors say when `tell` refuses a text over `TELL_TEXT_MAX`. */
166 export const TOO_LONG_WORDS = TELL_LIMIT_WORDS;
167167
168168 /** What happened, in the sentence both doors say. */
169169 export function toldWords(told: Told): string {
src/actions/tell_from.ts +10 −1
@@ -6,7 +6,16 @@
66 import { scrubQuery } from "./tell_context.ts";
77
88 /** The most characters a tell's words may have; every door refuses more. */
9 export const TELL_TEXT_MAX = 2000;
9 export const TELL_TEXT_MAX = 4000;
10
11 /** The one sentence every tell box shows and every refusal opens with: the limit, in characters. */
outdated

Comment is garbled ("Counted in characters, not bytes: what every door says..."). Say what the constant is. The stale comment on TOO_LONG_WORDS in src/actions/tell.ts ("over MAX_BODY") is also now wrong. The literal 4000 in src/apps/toolbar.ts duplicates TELL_TEXT_MAX; a test should pin them together.

12 export const TELL_LIMIT_WORDS = "One thought, at most 4,000 characters.";
13
14 /** What a refused tell is told to do about it. */
15 export const TELL_LIMIT_HINT = "Shorten it to 4,000 characters or fewer, or send the rest as a second tell.";
16
17 /** Whether these words are over the limit (UTF-16 characters, as `maxlength` counts). */
18 export const overTellLimit = (text: string): boolean => text.length > TELL_TEXT_MAX;
1019
1120 /** The longest `from` a tell may carry. */
1221 export const FROM_MAX = 512;
src/apps/toolbar.ts +2 −1
@@ -15,6 +15,7 @@
1515 */
1616
1717 import { staticResponse } from "../web/asset.ts";
18 import { TELL_TEXT_MAX } from "../actions/tell_from.ts";
1819 import { sha256 } from "../kernel/hash.ts";
1920 import { TOUR_ASSET_PATH } from "./tour.ts";
2021 import type { ReviewStep } from "../core/review_steps.ts";
@@ -185,7 +186,7 @@ const toolbarSource = `(function () {
185186 tellHint.textContent = "What should be better here? The people who build this will read it.";
186187 tellHint.style.cssText = "opacity:.85";
187188 var tellText = document.createElement("textarea");
188 tellText.maxLength = 2000;
189 tellText.maxLength = ${TELL_TEXT_MAX};
189190 tellText.rows = 3;
190191 tellText.required = true;
191192 tellText.id = "forge-note";
src/http/feed.ts +3 −3
@@ -11,7 +11,7 @@ import {
1111 UNVERIFIED_WORDS,
1212 VARIANTS_MAX,
1313 } from "../actions/tell.ts";
14 import { parseFrom, TELL_TEXT_MAX } from "../actions/tell_from.ts";
14 import { overTellLimit, parseFrom, TELL_LIMIT_HINT, TELL_LIMIT_WORDS, TELL_TEXT_MAX } from "../actions/tell_from.ts";
1515 import { DIRECTION_NOTE } from "../crew/direct.ts";
1616 import { readInteraction } from "../feed/interact.ts";
1717 import { likeLedger, parseLedgerBefore, setLike } from "../feed/likes.ts";
@@ -315,8 +315,8 @@ export function feedRoutes(router: Router<Handler>): void {
315315 const viewer = ctx.auth.user!;
316316 const input = await body(ctx.request);
317317 const text = str(input.text).trim();
318 if (text === "" || text.length > TELL_TEXT_MAX)
319 return apiError("invalid_text", 422, `text is 1 to ${TELL_TEXT_MAX} characters`);
318 if (overTellLimit(text)) return apiError("invalid_text", 422, TELL_LIMIT_WORDS, TELL_LIMIT_HINT);

The 422 {error,message,hint} path has no test at 4,000/4,001. Nothing fails if this line is removed. Add a route test asserting status 422, error, message containing 4,000 and a hint, and that 4,000 is accepted.

319 if (text === "") return apiError("invalid_text", 422, `text is 1 to ${TELL_TEXT_MAX.toLocaleString("en-US")} characters`);
320320 const variants = parseVariants(input.variants);
321321 if (variants === undefined)
322322 return apiError(
src/http/mcp/tools/tell.ts +4 −2
@@ -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 { parseFrom } from "../../../actions/tell_from.ts";
5 import { overTellLimit, parseFrom, TELL_LIMIT_HINT, TELL_LIMIT_WORDS } 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 { good, bad, type Tool, str, REPO_ARG, repoArg, isAnswer } from "../shared.ts";
@@ -16,7 +16,7 @@ export const tool: Tool = {
1616 type: "object",
1717 properties: {
1818 repo: REPO_ARG,
19 text: { type: "string", maxLength: 8000 },
19 text: { type: "string", maxLength: 4000 },
2020 from: {
2121 type: "string",
2222 maxLength: 512,
@@ -59,6 +59,8 @@ export const tool: Tool = {
5959 "text is a string of at most 20,000 characters",
6060 );
6161 }
62 if (overTellLimit(str(args["text"]).trim()))
63 return bad("invalid", `${TELL_LIMIT_WORDS} ${TELL_LIMIT_HINT}`);
6264 const repo = repoArg(ctx, user, args);
6365 if (isAnswer(repo)) return repo;
6466 const where = parseContext(args["context"]);
src/http/respond.ts +2 −1
@@ -151,7 +151,8 @@ export const apiError = (
151151 code: string,
152152 status: number,
153153 message: string,
154 ): Response => json({ error: code, message }, status);
154 hint?: string,
155 ): Response => json(hint === undefined ? { error: code, message } : { error: code, message, hint }, status);
155156
156157 /** The API's own words for a resource that is missing or not visible to you. */
157158 export const NOT_FOUND_WORDS = "no such resource here, or it is not visible to you";
src/web/pages/thread.ts +4 −2
@@ -8,6 +8,7 @@
88 * is what makes a long thread skimmable.
99 */
1010
11 import { TELL_LIMIT_WORDS, TELL_TEXT_MAX } from "../../actions/tell_from.ts";
1112 import { returnTo, withReturn } from "../return_to.ts";
1213 import { mayView } from "../../core/sealed.ts";
1314 import { THREAD_SAYS } from "../../actions/thread_words.ts";
@@ -709,10 +710,11 @@ export function composer(ctx: Ctx, o: ComposerOptions): Html {
709710 id="comment-body"
710711 name="text"
711712 rows="${String(tell.rows ?? 4)}"
712 maxlength="2000"
713 maxlength="${String(TELL_TEXT_MAX)}"
713714 placeholder="Tell the crew what should change"
714715 required
715 >${tell.text ?? ""}</textarea>`
716 >${tell.text ?? ""}</textarea>
717 <p class="muted small">${TELL_LIMIT_WORDS}</p>`
716718 : formField(
717719 kept(refusedHere(ctx), {
718720 label: "Comment",
src/web/share_target.ts +2 −1
@@ -7,6 +7,7 @@
77 * A share arrives as `GET /?title=…&text=…&url=…`; the composer opens with
88 * those words as a draft; Post is `POST /tell` with the fields below.
99 */
10 import { TELL_TEXT_MAX } from "../actions/tell_from.ts";
1011 import type { URLSearchParams as Params } from "node:url";
1112
1213 /** The query parameters a share carries, in the order they are joined. */
@@ -16,7 +17,7 @@ export const SHARE_PARAMS = { title: "title", text: "text", url: "url" } as cons
1617 export const SHARE_TARGET = { action: "/tell", method: "GET", params: SHARE_PARAMS } as const;
1718
1819 /** The longest tell the composer takes (its textarea's `maxlength`). */
19 export const TELL_MAX = 2000;
20 export const TELL_MAX = TELL_TEXT_MAX;
2021
2122 /**
2223 * Why these words cannot be a tell, in one sentence naming the limit, or undefined when they can:
src/web/studio/actions.ts +3 −1
@@ -14,7 +14,7 @@ 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 { parseFrom } from "../../actions/tell_from.ts";
17 import { overTellLimit, parseFrom } from "../../actions/tell_from.ts";
1818 import { SENT_WORDS, tell, toldWords, TOO_LONG_WORDS } from "../../actions/tell.ts";
1919 import { contextNote, parseContext } from "../../actions/tell_context.ts";
2020 import { refusalWords } from "../../actions/tell_answer.ts";
@@ -77,6 +77,7 @@ async function tellFrom(
7777 tone: "danger",
7878 message: SAY_SOMETHING_WORDS,
7979 });
80 if (overTellLimit(text)) return flashOrJson(ctx, back, { tone: "danger", message: TOO_LONG_WORDS });
8081 return toldAnswer(ctx, repo, form, back, from, await tell(ctx.app, ctx.auth.user, repo, text, 1, from), onTold);
8182 }
8283
@@ -185,6 +186,7 @@ async function tellFromPage(ctx: Ctx, repo: Repo, form: Form): Promise<Response>
185186 return flashTo(ctx, back, { tone: "danger", message: NOT_TOLD_FROM_WORDS });
186187 const text = field(form, "text").trim();
187188 if (text === "") return flashTo(ctx, back, { tone: "danger", message: SAY_SOMETHING_WORDS });
189 if (overTellLimit(text)) return flashTo(ctx, back, { tone: "danger", message: TOO_LONG_WORDS });
188190 const told = await tell(ctx.app, ctx.auth.user, repo, `${text}${contextNote(where, { preview: true, app: repo.name })}`);
189191 if (!told.ok)
190192 return flashTo(ctx, back, {
src/web/studio/app.ts +3 −2
@@ -19,7 +19,7 @@ import { egressNote } from "./egress.ts";
1919 import { audit } from "../../contract/audit.ts";
2020 import { latestProbes } from "../../contract/probes.ts";
2121 import { appsRuntime, envsFor } from "../../apps/runtime.ts";
22 import { MAX_BODY } from "../../core/issues.ts";
22 import { TELL_LIMIT_WORDS, TELL_TEXT_MAX } from "../../actions/tell_from.ts";
2323 import { listCrewRoles } from "../../core/agents.ts";
2424 import type { AppRecord } from "../../core/apps.ts";
2525 import type { DecisionStat } from "../../core/decisions.ts";
@@ -341,10 +341,11 @@ export async function studioApp(
341341 id="tell"
342342 name="text"
343343 required
344 maxlength="${MAX_BODY}"
344 maxlength="${String(TELL_TEXT_MAX)}"
345345 placeholder="Tell the crew…"
346346 />
347347 ${btn("Tell", { variant: "primary", type: "submit" })}
348 <span class="muted small">${TELL_LIMIT_WORDS}</span>
348349 </form>
349350 ${builders.length === 0
350351 ? html`<p class="muted small">
src/web/studio/feed.ts +4 −1
@@ -8,6 +8,7 @@
88 * Every string on a card is plain text and is escaped here, once.
99 */
1010
11 import { TELL_LIMIT_WORDS, TELL_TEXT_MAX } from "../../actions/tell_from.ts";
1112 import { COMPOSER_FIELDS, TELL_MAX, sharedDraft, shareToken } from "../share_target.ts";
1213 import { chipCounts } from "../../feed/chips.ts";
1314 import { chipsOf, KIND_CHIPS, type KindChip } from "../../core/feed_chips.ts";
@@ -207,7 +208,8 @@ export function feedCard(
207208 <span class="bar">${btn("Reply", { size: "sm", variant: "primary" })}</span>
208209 </form>`
209210 : null}<form method="post" action="${target ?? `/${item.app}/tell`}" class="stack">
outdated

Same as the thread composer: maxlength is set but the limit is never said on this box. Also the steer box on this card now takes 4,000 with no server-side check at that door.

210 <textarea class="input" name="text" rows="2" maxlength="2000" required aria-label="${target ? "Steer this run" : "Tell the crew"}"></textarea>
211 <textarea class="input" name="text" rows="2" maxlength="${target ? "2000" : String(TELL_TEXT_MAX)}" required aria-label="${target ? "Steer this run" : "Tell the crew"}"></textarea>
212 ${target ? null : html`<span class="muted small">${TELL_LIMIT_WORDS}</span>`}
211213 <span class="bar">${btn(target ? "Steer" : "Tell", reply ? { size: "sm" } : { size: "sm", variant: "primary" })}</span>
212214 </form>
213215 <span class="bar">
@@ -291,6 +293,7 @@ export function composer(ctx: Ctx, user: User): Html {
291293 <input type="hidden" name="${COMPOSER_FIELDS.back}" value="/feed" />
292294 ${shared === "" ? "" : html`<input type="hidden" name="${COMPOSER_FIELDS.once}" value="${shareToken(user.id, shared)}" />`}
293295 <textarea class="input" name="${COMPOSER_FIELDS.text}" rows="2" maxlength="${String(TELL_MAX)}" required placeholder="Tell the crew what should change" aria-label="Tell the crew" aria-keyshortcuts="Control+Enter Meta+Enter" data-draft="${user.id}">${shared}</textarea>
296 <span class="muted small">${TELL_LIMIT_WORDS}</span>
294297 <div class="bar">
295298 ${repos.length === 0
296299 ? html`<input type="hidden" name="${COMPOSER_FIELDS.app}" value="${FORGE_TARGET}" /><span class="muted small">the forge</span>`
src/web/studio/living.ts +2
@@ -16,6 +16,7 @@ import { btn } from "../ui.ts";
1616 import { writableAppsOf } from "./asks.ts";
1717 import { FORGE_TARGET, NEW_APP_TARGET } from "./feed.ts";
1818 import { appsFirst } from "../../actions/first_ask.ts";
19 import { TELL_LIMIT_WORDS } from "../../actions/tell_from.ts";
1920 import { COMPOSER_FIELDS, TELL_MAX, sharedDraft, shareToken } from "../share_target.ts";
2021
2122 const NOW_TTL_MS = 3_000;
@@ -49,6 +50,7 @@ export function tellBox(ctx: Ctx, user: User): Html {
4950 <option value="${FORGE_TARGET}">the forge</option>
5051 </select>`}
5152 ${btn("Tell", { variant: "primary" })}
53 <span class="muted small">${TELL_LIMIT_WORDS}</span>
5254 </form>
5355 <p class="small muted home-doors">
5456 <a href="/notes" title="Your notes and where they stand">Notes</a>
src/web/studio/tell_form.ts +2
@@ -6,6 +6,7 @@
66 */
77 import { html, type Html } from "../html.ts";
88 import { btn } from "../ui.ts";
9 import { TELL_LIMIT_WORDS } from "../../actions/tell_from.ts";
910 import { COMPOSER_FIELDS, TELL_MAX } from "../share_target.ts";
1011
1112 export function tellForm(opts: { text: string; hidden: Html; aside?: Html; refusal?: string | undefined }): Html {
@@ -17,6 +18,7 @@ export function tellForm(opts: { text: string; hidden: Html; aside?: Html; refus
1718 <form class="stack" method="post" action="/tell">
1819 ${opts.hidden}
1920 <textarea class="input" name="${COMPOSER_FIELDS.text}" rows="6" ${limits} ${flags} aria-label="Tell the crew" data-keep>${opts.text}</textarea>
21 <span class="muted small">${TELL_LIMIT_WORDS}</span>
2022 <div class="bar">${opts.aside ?? html``}<span class="spacer"></span>${btn("Send", { variant: "primary" })}</div>
2123 </form>`;
2224 }
src/web/studio/toolbar.ts +3 −1
@@ -24,6 +24,7 @@ import { reportTitle } from "../../actions/page-report.ts";
2424 import { NOT_SENT_WORDS } from "../../actions/tell_words.ts";
2525 import { NOTE_TOO_LONG } from "../../apps/note_words.ts";
2626 import { getAppByRepo } from "../../core/apps.ts";
27 import { TELL_LIMIT_WORDS, TELL_TEXT_MAX } from "../../actions/tell_from.ts";
2728 import { getIssue, MAX_BODY } from "../../core/issues.ts";
2829 import { diffBetween, getPull, pullDir, type Pull } from "../../core/pulls.ts";
2930 import { canRead, canWrite, type Repo } from "../../core/repos.ts";
@@ -259,7 +260,8 @@ export async function toolbarPage(ctx: Ctx): Promise<Response> {
259260 : html`<input type="hidden" name="page" value="${address}" />
260261 ${when(pull !== undefined, () => html`<input type="hidden" name="pull" value="${pull!.number}" />`)}`}
261262 <label>Tell the crew
262 <textarea name="text" rows="3" maxlength="${MAX_BODY}" required data-keep></textarea>
263 <textarea name="text" rows="3" maxlength="${String(TELL_TEXT_MAX)}" required data-keep></textarea>
264 <span class="muted small">${TELL_LIMIT_WORDS}</span>
263265 </label>
264266 <div class="form-actions">${btn("Tell", { variant: "primary" })}</div>
265267 </form>`,
test/mcp-tell.test.ts +1 −1
@@ -104,7 +104,7 @@ describe("MCP tell refusals", () => {
104104 test("every refusal the composer words is worded by the shared function", () => {
105105 expect(refusalWords("empty")).toBe(SAY_SOMETHING_WORDS);
106106 expect(refusalWords("unverified")).toBe("Verify your email first."); // the one place the sentence is spelled out
107 expect(refusalWords("body_too_long")).toBe("That is too long to tell in one go.");
107 expect(refusalWords("body_too_long")).toBe("One thought, at most 4,000 characters.");
108108 expect(refusalWords("not_found")).toBe("That could not be told.");
109109 });
110110 });
test/share-target-tell.test.ts +4 −4
@@ -89,7 +89,7 @@ test("the last repository told is the one chosen", async () => {
8989 test("a share that cannot be a tell is refused with a sentence", async () => {
9090 const cases: [Record<string, string>, RegExp, number][] = [
9191 [{ title: " " }, /Nothing to tell yet/, 422],
92 [{ text: "x".repeat(2001) }, /too long/, 422],
92 [{ text: "x".repeat(4001) }, /too long/, 422],
9393 [{ title: "t", url: "javascript:alert(1)" }, /not a web address/, 400],
9494 [{ title: "t", url: "ftp://example.com/" }, /not a web address/, 400],
9595 [{ title: "t", url: "not a url" }, /not a web address/, 400],
@@ -136,9 +136,9 @@ test("where the last tell went decides: a tell to the forge after an issue choos
136136 });
137137
138138 test("a share the composer cannot hold whole is refused, not cut", async () => {
139 const res = await share({ text: "y".repeat(2001) });
139 const res = await share({ text: "y".repeat(4001) });
140140 expect(res.status).toBe(422);
141141 expect(await res.text()).toContain("none of it was sent");
142 const ok = await (await share({ text: "y".repeat(2000) })).text();
143 expect(ok).toContain("y".repeat(2000));
142 const ok = await (await share({ text: "y".repeat(4000) })).text();
143 expect(ok).toContain("y".repeat(4000));
144144 });
test/share-target.test.ts +1 −1
@@ -58,7 +58,7 @@ test("a share opens the composer with title, text and url joined, escaped", asyn
5858 test("an enormous share is cut to what the composer takes", async () => {
5959 const out = await (await fetch(`${servers.url}/?${shareQuery({ text: "x".repeat(6_000) })}`, { headers: { cookie } })).text();
6060 const area = /<input[^>]*name="text"[^>]*value="([^"]*)"/.exec(out)?.[1] ?? "";
61 expect(area.length).toBe(2000);
61 expect(area.length).toBe(4000);
6262 });
6363
6464 test("a signed-out sharer is sent to sign in with the way back, same-origin only", async () => {
test/share-tell-tui.test.ts +1 −1
@@ -19,7 +19,7 @@ test("a typed share: a trailing link is the link, the rest the text", () => {
1919 expect(p.get("text")).toBe("look at this");
2020 expect(refuseShare(parseShare(" "))).toMatch(/Nothing to tell yet/);
2121 expect(refuseShare(parseShare("go javascript:alert(1)"))).toMatch(/not a web address/);
22 expect(refuseShare(parseShare("x ".repeat(1500)))).toMatch(/too long/);
22 expect(refuseShare(parseShare("x ".repeat(2500)))).toMatch(/too long/);
2323 });
2424
2525 let dataDir: string;
test/tell-from-parse.test.ts +1 −1
@@ -23,5 +23,5 @@ test("a secret in the query is scrubbed, the path and fragment are kept", () =>
2323 });
2424
2525 test("the words limit is the one the doors share", () => {
26 expect(TELL_TEXT_MAX).toBe(2000);
26 expect(TELL_TEXT_MAX).toBe(4000);
2727 });
test/tell-limit-doors.test.ts added +111
@@ -0,0 +1,111 @@
1 /**
2 * The 4,000-character tell limit at the HTTP tell route, the web tell actions, and every tell box.
3 */
4 import { afterAll, beforeAll, expect, test } from "bun:test";
5 import { mkdtemp, rm } from "node:fs/promises";
6 import { tmpdir } from "node:os";
7 import { join } from "node:path";
8 import { createApp, type App } from "../src/app.ts";
9 import { createRepo } from "../src/actions/repos.ts";
10 import { TELL_LIMIT_WORDS, TELL_TEXT_MAX } from "../src/actions/tell_from.ts";
11 import { toolbarJs } from "../src/apps/toolbar.ts";
12 import { createToken } from "../src/core/tokens.ts";
13 import { createUser } from "../src/core/users.ts";
14 import { serve, type Servers } from "../src/http/server.ts";
15 import { quietLogs } from "./helpers/globals.ts";
16
17 quietLogs();
18
19 let dataDir: string;
20 let app: App;
21 let servers: Servers;
22 let cookie = "";
23 let token = "";
24
25 beforeAll(async () => {
26 dataDir = await mkdtemp(join(tmpdir(), "forge-tell-doors-"));
27 app = createApp({ dataDir, port: 0, host: "forge.test" });
28 servers = await serve(app);
29 const made = await createUser(app.db, {
30 origin: "seed", trusted: true, username: "alice", email: "[email protected]",
31 password: "a-good-passphrase", adminIfFirst: true,
32 });
33 if (!made.ok) throw new Error(made.error);
34 const res = await fetch(`${servers.url}/signin`, {
35 method: "POST",
36 body: new URLSearchParams({ username: "alice", password: "a-good-passphrase" }),
37 redirect: "manual",
38 });
39 cookie = (res.headers.get("set-cookie") ?? "").split(";")[0]!;
40 token = createToken(app.db, made.value.id, "t", "rw").token;
41 const repo = await createRepo(app, made.value, { name: "notes", visibility: "public" });
42 if (!repo.ok) throw new Error("repo failed");
43 }, 120_000);
44
45 afterAll(async () => {
46 servers.stop();
47 app.close();
48 await rm(dataDir, { recursive: true, force: true });
49 });
50
51 const issues = () => app.db.query<{ n: number }, []>("SELECT count(*) AS n FROM issue").get()!.n;
52
53 const api = (text: string) =>
54 fetch(`${servers.url}/api/v1/feed/tells`, {
55 method: "POST",
56 headers: { authorization: `Bearer ${token}`, "content-type": "application/json" },
57 body: JSON.stringify({ app: "alice/notes", text }),
58 });
59
60 test("the tell route accepts 4,000 and refuses 4,001 with error, message and hint", async () => {
61 const before = issues();
62 const over = await api("x".repeat(TELL_TEXT_MAX + 1));
63 expect(over.status).toBe(422);
64 const body = (await over.json()) as { error: string; message: string; hint: string };
65 expect(body.error).toBe("invalid_text");
66 expect(body.message).toContain("4,000");
67 expect(body.hint).toContain("4,000");
68 expect(issues()).toBe(before);
69 const at = await api("x".repeat(TELL_TEXT_MAX));
70 expect(at.status).toBe(201);
71 expect(issues()).toBe(before + 1);
72 });
73
74 const web = (path: string, fields: Record<string, string>) =>
75 fetch(`${servers.url}${path}`, {
76 method: "POST",
77 headers: { cookie, origin: servers.url },
78 body: new URLSearchParams(fields),
79 redirect: "manual",
80 });
81
82 test("the web tell action refuses 4,001 naming the limit and files nothing, and takes 4,000", async () => {
83 const before = issues();
84 const over = await web("/alice/notes/tell", { text: "y".repeat(TELL_TEXT_MAX + 1) });
85 expect(issues()).toBe(before);
86 const flash = decodeURIComponent(over.headers.get("set-cookie") ?? "") + (await over.text());
87 expect(flash).toContain("4,000");
88 const at = await web("/alice/notes/tell", { text: "y".repeat(TELL_TEXT_MAX) });
89 expect(at.status).toBeLessThan(400);
90 expect(issues()).toBe(before + 1);
91 });
92
93 test("the toolbar tell action refuses 4,001 naming the limit and files nothing", async () => {
94 const before = issues();
95 const over = await web("/alice/notes/tell", { text: "z".repeat(TELL_TEXT_MAX + 1), page: "http://forge.test/x" });
96 expect(issues()).toBe(before);
97 const flash = decodeURIComponent(over.headers.get("set-cookie") ?? "") + (await over.text());
98 expect(flash).toContain("4,000");
99 });
100
101 test("the toolbar's own box is cut at the shared limit", () => {
102 expect(toolbarJs).toContain(`tellText.maxLength = ${TELL_TEXT_MAX};`);
103 });
104
105 test("every tell box says the limit in one line", async () => {
106 const get = async (path: string) => (await fetch(`${servers.url}${path}`, { headers: { cookie } })).text();
107 for (const path of ["/", "/feed", "/alice/notes", "/alice/notes/issues/new", "/tell?text=" + "q".repeat(5)]) {
108 const page = await get(path);
109 if (page.includes('name="text"')) expect(page).toContain(TELL_LIMIT_WORDS);
110 }
111 });
test/tell-limit.test.ts added +50
@@ -0,0 +1,50 @@
1 /**
2 * A tell is one thought: 4,000 characters pass, 4,001 are refused naming the limit, at every door.
3 */
4 import { afterAll, beforeAll, expect, test } from "bun:test";
5 import { mkdtemp, rm } from "node:fs/promises";
6 import { tmpdir } from "node:os";
7 import { join } from "node:path";
8 import type { Ctx } from "../src/http/context.ts";
9 import { createApp, type App } from "../src/app.ts";
10 import { createRepo } from "../src/actions/repos.ts";
11 import { overTellLimit, TELL_TEXT_MAX } from "../src/actions/tell_from.ts";
12 import { tool } from "../src/http/mcp/tools/tell.ts";
13 import { seedAdmin } from "./helpers/admin.ts";
14 import { quietLogs } from "./helpers/globals.ts";
15
16 quietLogs();
17
18 let dataDir: string;
19 let app: App;
20
21 beforeAll(async () => {
22 dataDir = await mkdtemp(join(tmpdir(), "forge-tell-limit-"));
23 app = createApp({ dataDir, port: 0 });
24 });
25 afterAll(async () => {
26 app.close();
27 await rm(dataDir, { recursive: true, force: true });
28 });
29
30 test("the limit is 4,000 characters, counted as characters not bytes", () => {
31 expect(TELL_TEXT_MAX).toBe(4000);
32 expect(overTellLimit("a".repeat(4000))).toBe(false);
33 expect(overTellLimit("a".repeat(4001))).toBe(true);
34 // 4,000 two-byte characters are 8,000 bytes and still fit.
35 expect(overTellLimit("é".repeat(4000))).toBe(false);
36 });
37
38 test("the MCP tell tool refuses 4,001 naming 4,000, and accepts 4,000", async () => {

Only the MCP tool is exercised. The issue's box 3 needs the boundary proven at the tell route too, and the web tell action (studio/actions.ts overTellLimit branches, one of them new in the toolbar path) has no test at all.

39 const a = await seedAdmin(app, { username: "alice", email: "[email protected]", password: "a-long-tell-passphrase" });
40 if (!a.ok) throw new Error("signup failed");
41 const made = await createRepo(app, a.value, { name: "notes", visibility: "public" });
42 if (!made.ok) throw new Error("repo failed");
43 const url = new URL("http://localhost/mcp");
44 const ctx: Ctx = { app, request: new Request(url.href), url, params: {}, auth: { user: a.value, scope: "admin", via: "token" }, theme: undefined };
45 const over = await tool.run(ctx, a.value, { repo: "alice/notes", text: "x".repeat(4001) });
46 expect(over.ok).toBe(false);
47 if (!over.ok) expect(over.message).toContain("4,000");
48 const at = await tool.run(ctx, a.value, { repo: "alice/notes", text: "x".repeat(4000) });
49 expect(at.ok).toBe(true);
50 });
test/tell-refused.test.ts +5 −5
@@ -56,7 +56,7 @@ test("an empty tell answers 422, names the limit and files nothing", async () =>
5656 expect(res.status).toBe(422);
5757 const out = await res.text();
5858 expect(out).toContain("Nothing to tell yet");
59 expect(out).toContain("2,000 characters");
59 expect(out).toContain("4,000 characters");
6060 expect(out).toContain('<textarea');
6161 }
6262 expect(thoughts()).toBe(before);
@@ -68,7 +68,7 @@ test("a tell over the limit keeps the words, escaped, and names the limit", asyn
6868 const res = await post({ text, once: "0123456789abcdef01234567" });
6969 expect(res.status).toBe(422);
7070 const out = await res.text();
71 expect(out).toContain("at most 2,000 characters");
71 expect(out).toContain("at most 4,000 characters");
7272 expect(out).toContain("&lt;script&gt;alert(1)&lt;/script&gt;" + "x".repeat(TELL_MAX));
7373 expect(out).not.toContain("<script>alert(1)");
7474 expect(out).toContain('name="app" value="forge"');
@@ -100,14 +100,14 @@ test("the refusal is announced and the box is pointed at it", async () => {
100100 expect(out).toContain('aria-describedby="tell-refusal"');
101101 expect(out).toContain('aria-invalid="true"');
102102 expect(out).toContain("autofocus");
103 expect(out).not.toContain("At most 2,000 characters.");
103 expect(out).not.toContain("At most 4,000 characters.");
104104 });
105105
106106 test("the share-sheet path does the same: 422, the draft kept, the limit named", async () => {
107107 const long = await fetch(`${servers.url}/tell?text=${encodeURIComponent("<b>" + "z".repeat(TELL_MAX))}`, { headers: { cookie } });
108108 expect(long.status).toBe(422);
109109 const out = await long.text();
110 expect(out).toContain("at most 2,000 characters");
110 expect(out).toContain("at most 4,000 characters");
111111 expect(out).toContain("&lt;b&gt;" + "z".repeat(TELL_MAX));
112112 const empty = await fetch(`${servers.url}/tell?title=%20`, { headers: { cookie } });
113113 expect(empty.status).toBe(422);
@@ -123,5 +123,5 @@ test("a JSON asker still gets a 422 with the sentence", async () => {
123123 body: new URLSearchParams({ app: "forge", text: "" }),
124124 });
125125 expect(res.status).toBe(422);
126 expect(((await res.json()) as { error: string }).error).toContain("2,000");
126 expect(((await res.json()) as { error: string }).error).toContain("4,000");
127127 });
test/tell-stdin.test.ts +3 −3
@@ -82,11 +82,11 @@ test("invalid UTF-8 is refused", () => {
8282 expect(cleanPiped(new TextEncoder().encode("héllo")).kind).toBe("text");
8383 });
8484
85 test("piped text over the 2000-character limit is refused locally with both numbers", async () => {
85 test("piped text over the 4000-character limit is refused locally with both numbers", async () => {
8686 const before = seen.length;
87 const run = await pipe("a".repeat(3000));
87 const run = await pipe("a".repeat(5000));
8888 expect(run.code).toBe(EXIT.usage);
89 expect(run.err).toContain("piped text is 3000 characters and the limit is 2000");
89 expect(run.err).toContain("piped text is 5000 characters and the limit is 4000");
9090 expect(seen.length).toBe(before);
9191 });
9292

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs