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
Check · Review · Land · Live done — Landed and live in production.
scout/forge:scout/14139-a-tell-is-limited-to-4-000-characters-at → main 5 commits fork 5 threads · 5 unresolved
docs/mcp/tools/tell.md +1 −1
| @@ -30,7 +30,7 @@ this tool all use: | ||
| 30 | 30 | | error | words | |
| 31 | 31 | | --- | --- | |
| 32 | 32 | | `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. | | |
| 34 | 34 | | `unverified` | Verify your email first. | |
| 35 | 35 | | `forbidden` | the crew's direction note | |
| 36 | 36 | | 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"; | ||
| 17 | 17 | import { err, ok, type Result } from "../kernel/result.ts"; |
| 18 | 18 | import { requireParticipant } from "./access.ts"; |
| 19 | 19 | 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"; | |
| 21 | 21 | import { requireVerified } from "./verify.ts"; |
| 22 | 22 | import { VERIFY_FIRST } from "./verify_words.ts"; |
| 23 | 23 | |
| @@ -162,8 +162,8 @@ export async function tell( | ||
| 162 | 162 | /** What every door says when a tell is refused for an unverified address. */ |
| 163 | 163 | export const UNVERIFIED_WORDS = VERIFY_FIRST; |
| 164 | 164 | |
| 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; | |
| 167 | 167 | |
| 168 | 168 | /** What happened, in the sentence both doors say. */ |
| 169 | 169 | export function toldWords(told: Told): string { |
src/actions/tell_from.ts +10 −1
| @@ -6,7 +6,16 @@ | ||
| 6 | 6 | import { scrubQuery } from "./tell_context.ts"; |
| 7 | 7 | |
| 8 | 8 | /** 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. */ | |
| 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; | |
| 10 | 19 | |
| 11 | 20 | /** The longest `from` a tell may carry. */ |
| 12 | 21 | export const FROM_MAX = 512; |
src/apps/toolbar.ts +2 −1
| @@ -15,6 +15,7 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | |
| 17 | 17 | import { staticResponse } from "../web/asset.ts"; |
| 18 | import { TELL_TEXT_MAX } from "../actions/tell_from.ts"; | |
| 18 | 19 | import { sha256 } from "../kernel/hash.ts"; |
| 19 | 20 | import { TOUR_ASSET_PATH } from "./tour.ts"; |
| 20 | 21 | import type { ReviewStep } from "../core/review_steps.ts"; |
| @@ -185,7 +186,7 @@ const toolbarSource = `(function () { | ||
| 185 | 186 | tellHint.textContent = "What should be better here? The people who build this will read it."; |
| 186 | 187 | tellHint.style.cssText = "opacity:.85"; |
| 187 | 188 | var tellText = document.createElement("textarea"); |
| 188 | tellText.maxLength = 2000; | |
| 189 | tellText.maxLength = ${TELL_TEXT_MAX}; | |
| 189 | 190 | tellText.rows = 3; |
| 190 | 191 | tellText.required = true; |
| 191 | 192 | tellText.id = "forge-note"; |
src/http/feed.ts +3 −3
| @@ -11,7 +11,7 @@ import { | ||
| 11 | 11 | UNVERIFIED_WORDS, |
| 12 | 12 | VARIANTS_MAX, |
| 13 | 13 | } 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"; | |
| 15 | 15 | import { DIRECTION_NOTE } from "../crew/direct.ts"; |
| 16 | 16 | import { readInteraction } from "../feed/interact.ts"; |
| 17 | 17 | import { likeLedger, parseLedgerBefore, setLike } from "../feed/likes.ts"; |
| @@ -315,8 +315,8 @@ export function feedRoutes(router: Router<Handler>): void { | ||
| 315 | 315 | const viewer = ctx.auth.user!; |
| 316 | 316 | const input = await body(ctx.request); |
| 317 | 317 | 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`); | |
| 320 | 320 | const variants = parseVariants(input.variants); |
| 321 | 321 | if (variants === undefined) |
| 322 | 322 | return apiError( |
src/http/mcp/tools/tell.ts +4 −2
| @@ -2,7 +2,7 @@ import { contextNote, parseContext } from "../../../actions/tell_context.ts"; | ||
| 2 | 2 | import { asksMakeANewApp, firstAsk } from "../../../actions/first_ask.ts"; |
| 3 | 3 | import { crewCanRun } from "../../../web/studio/crew_key.ts"; |
| 4 | 4 | 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"; | |
| 6 | 6 | import { FROM_WORDS, tell, toldWords } from "../../../actions/tell.ts"; |
| 7 | 7 | import { refusalWords } from "../../../actions/tell_answer.ts"; |
| 8 | 8 | import { good, bad, type Tool, str, REPO_ARG, repoArg, isAnswer } from "../shared.ts"; |
| @@ -16,7 +16,7 @@ export const tool: Tool = { | ||
| 16 | 16 | type: "object", |
| 17 | 17 | properties: { |
| 18 | 18 | repo: REPO_ARG, |
| 19 | text: { type: "string", maxLength: 8000 }, | |
| 19 | text: { type: "string", maxLength: 4000 }, | |
| 20 | 20 | from: { |
| 21 | 21 | type: "string", |
| 22 | 22 | maxLength: 512, |
| @@ -59,6 +59,8 @@ export const tool: Tool = { | ||
| 59 | 59 | "text is a string of at most 20,000 characters", |
| 60 | 60 | ); |
| 61 | 61 | } |
| 62 | if (overTellLimit(str(args["text"]).trim())) | |
| 63 | return bad("invalid", `${TELL_LIMIT_WORDS} ${TELL_LIMIT_HINT}`); | |
| 62 | 64 | const repo = repoArg(ctx, user, args); |
| 63 | 65 | if (isAnswer(repo)) return repo; |
| 64 | 66 | const where = parseContext(args["context"]); |
src/http/respond.ts +2 −1
| @@ -151,7 +151,8 @@ export const apiError = ( | ||
| 151 | 151 | code: string, |
| 152 | 152 | status: number, |
| 153 | 153 | 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); | |
| 155 | 156 | |
| 156 | 157 | /** The API's own words for a resource that is missing or not visible to you. */ |
| 157 | 158 | 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 @@ | ||
| 8 | 8 | * is what makes a long thread skimmable. |
| 9 | 9 | */ |
| 10 | 10 | |
| 11 | import { TELL_LIMIT_WORDS, TELL_TEXT_MAX } from "../../actions/tell_from.ts"; | |
| 11 | 12 | import { returnTo, withReturn } from "../return_to.ts"; |
| 12 | 13 | import { mayView } from "../../core/sealed.ts"; |
| 13 | 14 | import { THREAD_SAYS } from "../../actions/thread_words.ts"; |
| @@ -709,10 +710,11 @@ export function composer(ctx: Ctx, o: ComposerOptions): Html { | ||
| 709 | 710 | id="comment-body" |
| 710 | 711 | name="text" |
| 711 | 712 | rows="${String(tell.rows ?? 4)}" |
| 712 | maxlength="2000" | |
| 713 | maxlength="${String(TELL_TEXT_MAX)}" | |
| 713 | 714 | placeholder="Tell the crew what should change" |
| 714 | 715 | required |
| 715 | >${tell.text ?? ""}</textarea>` | |
| 716 | >${tell.text ?? ""}</textarea> | |
| 717 | <p class="muted small">${TELL_LIMIT_WORDS}</p>` | |
| 716 | 718 | : formField( |
| 717 | 719 | kept(refusedHere(ctx), { |
| 718 | 720 | label: "Comment", |
src/web/studio/actions.ts +3 −1
| @@ -14,7 +14,7 @@ import { mayView } from "../../core/sealed.ts"; | ||
| 14 | 14 | import { shipsPastReviews } from "./land_as_is.ts"; |
| 15 | 15 | import { holdPull, releasePull } from "../../actions/holds.ts"; |
| 16 | 16 | import { addComment } from "../../actions/issues.ts"; |
| 17 | import { parseFrom } from "../../actions/tell_from.ts"; | |
| 17 | import { overTellLimit, parseFrom } from "../../actions/tell_from.ts"; | |
| 18 | 18 | import { SENT_WORDS, tell, toldWords, TOO_LONG_WORDS } from "../../actions/tell.ts"; |
| 19 | 19 | import { contextNote, parseContext } from "../../actions/tell_context.ts"; |
| 20 | 20 | import { refusalWords } from "../../actions/tell_answer.ts"; |
| @@ -77,6 +77,7 @@ async function tellFrom( | ||
| 77 | 77 | tone: "danger", |
| 78 | 78 | message: SAY_SOMETHING_WORDS, |
| 79 | 79 | }); |
| 80 | if (overTellLimit(text)) return flashOrJson(ctx, back, { tone: "danger", message: TOO_LONG_WORDS }); | |
| 80 | 81 | return toldAnswer(ctx, repo, form, back, from, await tell(ctx.app, ctx.auth.user, repo, text, 1, from), onTold); |
| 81 | 82 | } |
| 82 | 83 | |
| @@ -185,6 +186,7 @@ async function tellFromPage(ctx: Ctx, repo: Repo, form: Form): Promise<Response> | ||
| 185 | 186 | return flashTo(ctx, back, { tone: "danger", message: NOT_TOLD_FROM_WORDS }); |
| 186 | 187 | const text = field(form, "text").trim(); |
| 187 | 188 | 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 }); | |
| 188 | 190 | const told = await tell(ctx.app, ctx.auth.user, repo, `${text}${contextNote(where, { preview: true, app: repo.name })}`); |
| 189 | 191 | if (!told.ok) |
| 190 | 192 | return flashTo(ctx, back, { |
src/web/studio/app.ts +3 −2
| @@ -19,7 +19,7 @@ import { egressNote } from "./egress.ts"; | ||
| 19 | 19 | import { audit } from "../../contract/audit.ts"; |
| 20 | 20 | import { latestProbes } from "../../contract/probes.ts"; |
| 21 | 21 | 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"; | |
| 23 | 23 | import { listCrewRoles } from "../../core/agents.ts"; |
| 24 | 24 | import type { AppRecord } from "../../core/apps.ts"; |
| 25 | 25 | import type { DecisionStat } from "../../core/decisions.ts"; |
| @@ -341,10 +341,11 @@ export async function studioApp( | ||
| 341 | 341 | id="tell" |
| 342 | 342 | name="text" |
| 343 | 343 | required |
| 344 | maxlength="${MAX_BODY}" | |
| 344 | maxlength="${String(TELL_TEXT_MAX)}" | |
| 345 | 345 | placeholder="Tell the crew…" |
| 346 | 346 | /> |
| 347 | 347 | ${btn("Tell", { variant: "primary", type: "submit" })} |
| 348 | <span class="muted small">${TELL_LIMIT_WORDS}</span> | |
| 348 | 349 | </form> |
| 349 | 350 | ${builders.length === 0 |
| 350 | 351 | ? html`<p class="muted small"> |
src/web/studio/feed.ts +4 −1
| @@ -8,6 +8,7 @@ | ||
| 8 | 8 | * Every string on a card is plain text and is escaped here, once. |
| 9 | 9 | */ |
| 10 | 10 | |
| 11 | import { TELL_LIMIT_WORDS, TELL_TEXT_MAX } from "../../actions/tell_from.ts"; | |
| 11 | 12 | import { COMPOSER_FIELDS, TELL_MAX, sharedDraft, shareToken } from "../share_target.ts"; |
| 12 | 13 | import { chipCounts } from "../../feed/chips.ts"; |
| 13 | 14 | import { chipsOf, KIND_CHIPS, type KindChip } from "../../core/feed_chips.ts"; |
| @@ -207,7 +208,8 @@ export function feedCard( | ||
| 207 | 208 | <span class="bar">${btn("Reply", { size: "sm", variant: "primary" })}</span> |
| 208 | 209 | </form>` |
| 209 | 210 | : 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>`} | |
| 211 | 213 | <span class="bar">${btn(target ? "Steer" : "Tell", reply ? { size: "sm" } : { size: "sm", variant: "primary" })}</span> |
| 212 | 214 | </form> |
| 213 | 215 | <span class="bar"> |
| @@ -291,6 +293,7 @@ export function composer(ctx: Ctx, user: User): Html { | ||
| 291 | 293 | <input type="hidden" name="${COMPOSER_FIELDS.back}" value="/feed" /> |
| 292 | 294 | ${shared === "" ? "" : html`<input type="hidden" name="${COMPOSER_FIELDS.once}" value="${shareToken(user.id, shared)}" />`} |
| 293 | 295 | <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> | |
| 294 | 297 | <div class="bar"> |
| 295 | 298 | ${repos.length === 0 |
| 296 | 299 | ? 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"; | ||
| 16 | 16 | import { writableAppsOf } from "./asks.ts"; |
| 17 | 17 | import { FORGE_TARGET, NEW_APP_TARGET } from "./feed.ts"; |
| 18 | 18 | import { appsFirst } from "../../actions/first_ask.ts"; |
| 19 | import { TELL_LIMIT_WORDS } from "../../actions/tell_from.ts"; | |
| 19 | 20 | import { COMPOSER_FIELDS, TELL_MAX, sharedDraft, shareToken } from "../share_target.ts"; |
| 20 | 21 | |
| 21 | 22 | const NOW_TTL_MS = 3_000; |
| @@ -49,6 +50,7 @@ export function tellBox(ctx: Ctx, user: User): Html { | ||
| 49 | 50 | <option value="${FORGE_TARGET}">the forge</option> |
| 50 | 51 | </select>`} |
| 51 | 52 | ${btn("Tell", { variant: "primary" })} |
| 53 | <span class="muted small">${TELL_LIMIT_WORDS}</span> | |
| 52 | 54 | </form> |
| 53 | 55 | <p class="small muted home-doors"> |
| 54 | 56 | <a href="/notes" title="Your notes and where they stand">Notes</a> |
src/web/studio/tell_form.ts +2
| @@ -6,6 +6,7 @@ | ||
| 6 | 6 | */ |
| 7 | 7 | import { html, type Html } from "../html.ts"; |
| 8 | 8 | import { btn } from "../ui.ts"; |
| 9 | import { TELL_LIMIT_WORDS } from "../../actions/tell_from.ts"; | |
| 9 | 10 | import { COMPOSER_FIELDS, TELL_MAX } from "../share_target.ts"; |
| 10 | 11 | |
| 11 | 12 | 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 | ||
| 17 | 18 | <form class="stack" method="post" action="/tell"> |
| 18 | 19 | ${opts.hidden} |
| 19 | 20 | <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> | |
| 20 | 22 | <div class="bar">${opts.aside ?? html``}<span class="spacer"></span>${btn("Send", { variant: "primary" })}</div> |
| 21 | 23 | </form>`; |
| 22 | 24 | } |
src/web/studio/toolbar.ts +3 −1
| @@ -24,6 +24,7 @@ import { reportTitle } from "../../actions/page-report.ts"; | ||
| 24 | 24 | import { NOT_SENT_WORDS } from "../../actions/tell_words.ts"; |
| 25 | 25 | import { NOTE_TOO_LONG } from "../../apps/note_words.ts"; |
| 26 | 26 | import { getAppByRepo } from "../../core/apps.ts"; |
| 27 | import { TELL_LIMIT_WORDS, TELL_TEXT_MAX } from "../../actions/tell_from.ts"; | |
| 27 | 28 | import { getIssue, MAX_BODY } from "../../core/issues.ts"; |
| 28 | 29 | import { diffBetween, getPull, pullDir, type Pull } from "../../core/pulls.ts"; |
| 29 | 30 | import { canRead, canWrite, type Repo } from "../../core/repos.ts"; |
| @@ -259,7 +260,8 @@ export async function toolbarPage(ctx: Ctx): Promise<Response> { | ||
| 259 | 260 | : html`<input type="hidden" name="page" value="${address}" /> |
| 260 | 261 | ${when(pull !== undefined, () => html`<input type="hidden" name="pull" value="${pull!.number}" />`)}`} |
| 261 | 262 | <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> | |
| 263 | 265 | </label> |
| 264 | 266 | <div class="form-actions">${btn("Tell", { variant: "primary" })}</div> |
| 265 | 267 | </form>`, |
test/mcp-tell.test.ts +1 −1
| @@ -104,7 +104,7 @@ describe("MCP tell refusals", () => { | ||
| 104 | 104 | test("every refusal the composer words is worded by the shared function", () => { |
| 105 | 105 | expect(refusalWords("empty")).toBe(SAY_SOMETHING_WORDS); |
| 106 | 106 | 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."); | |
| 108 | 108 | expect(refusalWords("not_found")).toBe("That could not be told."); |
| 109 | 109 | }); |
| 110 | 110 | }); |
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", () => | ||
| 23 | 23 | }); |
| 24 | 24 | |
| 25 | 25 | test("the words limit is the one the doors share", () => { |
| 26 | expect(TELL_TEXT_MAX).toBe(2000); | |
| 26 | expect(TELL_TEXT_MAX).toBe(4000); | |
| 27 | 27 | }); |
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 () => | ||
| 56 | 56 | expect(res.status).toBe(422); |
| 57 | 57 | const out = await res.text(); |
| 58 | 58 | expect(out).toContain("Nothing to tell yet"); |
| 59 | expect(out).toContain("2,000 characters"); | |
| 59 | expect(out).toContain("4,000 characters"); | |
| 60 | 60 | expect(out).toContain('<textarea'); |
| 61 | 61 | } |
| 62 | 62 | expect(thoughts()).toBe(before); |
| @@ -68,7 +68,7 @@ test("a tell over the limit keeps the words, escaped, and names the limit", asyn | ||
| 68 | 68 | const res = await post({ text, once: "0123456789abcdef01234567" }); |
| 69 | 69 | expect(res.status).toBe(422); |
| 70 | 70 | const out = await res.text(); |
| 71 | expect(out).toContain("at most 2,000 characters"); | |
| 71 | expect(out).toContain("at most 4,000 characters"); | |
| 72 | 72 | expect(out).toContain("<script>alert(1)</script>" + "x".repeat(TELL_MAX)); |
| 73 | 73 | expect(out).not.toContain("<script>alert(1)"); |
| 74 | 74 | expect(out).toContain('name="app" value="forge"'); |
| @@ -100,14 +100,14 @@ test("the refusal is announced and the box is pointed at it", async () => { | ||
| 100 | 100 | expect(out).toContain('aria-describedby="tell-refusal"'); |
| 101 | 101 | expect(out).toContain('aria-invalid="true"'); |
| 102 | 102 | expect(out).toContain("autofocus"); |
| 103 | expect(out).not.toContain("At most 2,000 characters."); | |
| 103 | expect(out).not.toContain("At most 4,000 characters."); | |
| 104 | 104 | }); |
| 105 | 105 | |
| 106 | 106 | test("the share-sheet path does the same: 422, the draft kept, the limit named", async () => { |
| 107 | 107 | const long = await fetch(`${servers.url}/tell?text=${encodeURIComponent("<b>" + "z".repeat(TELL_MAX))}`, { headers: { cookie } }); |
| 108 | 108 | expect(long.status).toBe(422); |
| 109 | 109 | const out = await long.text(); |
| 110 | expect(out).toContain("at most 2,000 characters"); | |
| 110 | expect(out).toContain("at most 4,000 characters"); | |
| 111 | 111 | expect(out).toContain("<b>" + "z".repeat(TELL_MAX)); |
| 112 | 112 | const empty = await fetch(`${servers.url}/tell?title=%20`, { headers: { cookie } }); |
| 113 | 113 | expect(empty.status).toBe(422); |
| @@ -123,5 +123,5 @@ test("a JSON asker still gets a 422 with the sentence", async () => { | ||
| 123 | 123 | body: new URLSearchParams({ app: "forge", text: "" }), |
| 124 | 124 | }); |
| 125 | 125 | 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"); | |
| 127 | 127 | }); |
test/tell-stdin.test.ts +3 −3
| @@ -82,11 +82,11 @@ test("invalid UTF-8 is refused", () => { | ||
| 82 | 82 | expect(cleanPiped(new TextEncoder().encode("héllo")).kind).toBe("text"); |
| 83 | 83 | }); |
| 84 | 84 | |
| 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 () => { | |
| 86 | 86 | const before = seen.length; |
| 87 | const run = await pipe("a".repeat(3000)); | |
| 87 | const run = await pipe("a".repeat(5000)); | |
| 88 | 88 | 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"); | |
| 90 | 90 | expect(seen.length).toBe(before); |
| 91 | 91 | }); |
| 92 | 92 |
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.