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
Check · Review · Land · Live done — Landed and live in production.
scout/forge:scout/15109-a-tell-longer-than-the-limit-is-refused → main 11 commits fork 7 threads · 7 unresolved
src/actions/first_ask.ts +3 −4
| @@ -21,11 +21,10 @@ import { newAppFromSentence, NEW_APP_ERRORS } from "./apps.ts"; | ||
| 21 | 21 | import { getRepoById } from "../core/repos.ts"; |
| 22 | 22 | import { seatFirstAskCrew } from "../spawn/starter_crew.ts"; |
| 23 | 23 | 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"; | |
| 26 | 26 | import { deriveAppName } from "../web/pages/apps-name.ts"; |
| 27 | 27 | import { requireVerified } from "./verify.ts"; |
| 28 | import { MAX_BODY } from "../core/issues.ts"; | |
| 29 | 28 | import { recordRefusal } from "../core/first_ask_refusals.ts"; |
| 30 | 29 | import { DIRECTION_NOTE } from "../crew/direct.ts"; |
| 31 | 30 | |
| @@ -67,7 +66,7 @@ export async function firstAsk( | ||
| 67 | 66 | // Everything the tell could refuse is asked before the app exists, so a |
| 68 | 67 | // refused ask leaves nothing behind and a retry makes no second app. The |
| 69 | 68 | // 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)); | |
| 71 | 70 | if (actor === undefined || actor.kind === "org") return refuse(DIRECTION_NOTE); |
| 72 | 71 | if (!requireVerified(app, actor).ok) return refuse("Verify your email first."); |
| 73 | 72 | if (from !== null && typeof parseFrom(from) !== "string") return refuse(FROM_WORDS); |
src/actions/tell.ts +6 −7
| @@ -8,7 +8,7 @@ | ||
| 8 | 8 | |
| 9 | 9 | import type { App } from "../app.ts"; |
| 10 | 10 | 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"; | |
| 12 | 12 | import type { Repo } from "../core/repos.ts"; |
| 13 | 13 | import { listRuns } from "../core/runs.ts"; |
| 14 | 14 | import type { User } from "../core/users.ts"; |
| @@ -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, TELL_LIMIT_WORDS } from "./tell_from.ts"; | |
| 20 | import { overTellLimit, parseFrom } from "./tell_from.ts"; | |
| 21 | 21 | import { requireVerified } from "./verify.ts"; |
| 22 | 22 | import { VERIFY_FIRST } from "./verify_words.ts"; |
| 23 | 23 | |
| @@ -98,8 +98,10 @@ export async function tell( | ||
| 98 | 98 | if (!requireVerified(app, participant.value).ok) return err("unverified"); |
| 99 | 99 | const text = said.trim(); |
| 100 | 100 | 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
|
||
| 103 | // every caller. | |
outdated
Non-blocking: this comment line passes 100 columns; wrap it. |
||
| 104 | if (overTellLimit(text)) return err("body_too_long"); | |
| 103 | 105 | if (from !== null && !(fromApp && APP_ADDRESS.test(from))) { |
| 104 | 106 | const path = parseFrom(from); |
| 105 | 107 | if (typeof path !== "string") return err("bad_from"); |
| @@ -162,9 +164,6 @@ export async function tell( | ||
| 162 | 164 | /** What every door says when a tell is refused for an unverified address. */ |
| 163 | 165 | export const UNVERIFIED_WORDS = VERIFY_FIRST; |
| 164 | 166 | |
| 165 | /** What both doors say when `tell` refuses a text over `TELL_TEXT_MAX`. */ | |
| 166 | export const TOO_LONG_WORDS = TELL_LIMIT_WORDS; | |
| 167 | ||
| 168 | 167 | /** What happened, in the sentence both doors say. */ |
| 169 | 168 | export function toldWords(told: Told): string { |
| 170 | 169 | if (told.routed === undefined) |
src/actions/tell_answer.ts +11 −13
| @@ -3,7 +3,8 @@ | ||
| 3 | 3 | * (shared by the terminal screen and the ssh `tell` command). |
| 4 | 4 | */ |
| 5 | 5 | |
| 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"; | |
| 7 | 8 | import { NOT_TOLD_WORDS, SAY_SOMETHING_WORDS } from "./tell_words.ts"; |
| 8 | 9 | import { DIRECTION_NOTE } from "../crew/direct.ts"; |
| 9 | 10 | import type { Result } from "../kernel/result.ts"; |
| @@ -11,19 +12,16 @@ import type { Result } from "../kernel/result.ts"; | ||
| 11 | 12 | const SENTENCE_UNVERIFIED = `${UNVERIFIED_WORDS[0]!.toUpperCase()}${UNVERIFIED_WORDS.slice(1)}.`; |
| 12 | 13 | |
| 13 | 14 | /** 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; | |
| 24 | 21 | } |
outdated
The nested ternary is getting hard to read, and the optional |
||
| 25 | 22 | |
| 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" } { | |
| 27 | 25 | 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) }; | |
| 29 | 27 | } |
src/actions/tell_from.ts +4
| @@ -14,6 +14,10 @@ export const TELL_LIMIT_WORDS = "One thought, at most 4,000 characters."; | ||
| 14 | 14 | /** What a refused tell is told to do about it. */ |
| 15 | 15 | export const TELL_LIMIT_HINT = "Shorten it to 4,000 characters or fewer, or send the rest as a second tell."; |
| 16 | 16 | |
| 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 | ||
| 17 | 21 | /** Whether these words are over the limit (UTF-16 characters, as `maxlength` counts). */ |
| 18 | 22 | export const overTellLimit = (text: string): boolean => text.length > TELL_TEXT_MAX; |
| 19 | 23 |
src/http/feed.ts +2 −2
| @@ -13,7 +13,7 @@ import { | ||
| 13 | 13 | UNVERIFIED_WORDS, |
| 14 | 14 | VARIANTS_MAX, |
| 15 | 15 | } 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"; | |
| 17 | 17 | import { DIRECTION_NOTE } from "../crew/direct.ts"; |
| 18 | 18 | import { readInteraction } from "../feed/interact.ts"; |
| 19 | 19 | import { LEDGER_PAGE, likeLedger, parseLedgerBefore, setLike } from "../feed/likes.ts"; |
| @@ -313,7 +313,7 @@ export function feedRoutes(router: Router<Handler>): void { | ||
| 313 | 313 | const viewer = ctx.auth.user!; |
| 314 | 314 | const input = await body(ctx.request); |
| 315 | 315 | 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); | |
| 317 | 317 | if (text === "") return apiError("invalid_text", 422, `text is 1 to ${TELL_TEXT_MAX.toLocaleString("en-US")} characters`); |
| 318 | 318 | const variants = parseVariants(input.variants); |
| 319 | 319 | if (variants === undefined) |
src/http/mcp/tools/tell.ts +4 −4
| @@ -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 { 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"; | |
| 6 | 6 | import { FROM_WORDS, tell, toldWords } from "../../../actions/tell.ts"; |
| 7 | 7 | import { refusalWords } from "../../../actions/tell_answer.ts"; |
| 8 | 8 | import { mayReadRuns } from "../../../actions/runs.ts"; |
| @@ -65,8 +65,8 @@ export const tool: Tool = { | ||
| 65 | 65 | "text is a string of at most 20,000 characters", |
| 66 | 66 | ); |
| 67 | 67 | } |
| 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}`); | |
| 70 | 70 | const repo = repoArg(ctx, user, args); |
| 71 | 71 | if (isAnswer(repo)) return repo; |
| 72 | 72 | if (args["issue"] !== undefined) { |
| @@ -93,7 +93,7 @@ export const tool: Tool = { | ||
| 93 | 93 | 1, |
| 94 | 94 | from, |
| 95 | 95 | ); |
| 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 |
||
| 97 | 97 | return good({ |
| 98 | 98 | says: toldWords(told.value), |
| 99 | 99 | 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 { | ||
| 80 | 80 | onSubmit: (said) => { |
| 81 | 81 | if (said === "") return SAY_SOMETHING_WORDS; |
| 82 | 82 | 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()); | |
| 84 | 84 | ctx.toast(answer.text, answer.tone); |
| 85 | 85 | read(); |
| 86 | 86 | ctx.invalidate(); |
src/tui/screens/tell.ts +3 −3
| @@ -38,7 +38,7 @@ export function tellCommands(f: Session, ctx: Ctx, parent: () => Screen, repo: R | ||
| 38 | 38 | onSubmit: (said) => { |
| 39 | 39 | if (said === "") return SAY_SOMETHING_WORDS; |
| 40 | 40 | 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()); | |
| 42 | 42 | ctx.toast(answer.text, answer.tone); |
| 43 | 43 | })(); |
| 44 | 44 | }, |
| @@ -114,7 +114,7 @@ export async function tellFromPage( | ||
| 114 | 114 | repo, |
| 115 | 115 | `${said}${contextNote(where, { preview: true, app: named ? app : repo.name })}`, |
| 116 | 116 | ); |
| 117 | const answer = tellAnswer(told); | |
| 117 | const answer = tellAnswer(told, said.trim()); | |
| 118 | 118 | const left = dropped || (app !== undefined && !named); |
| 119 | 119 | ctx.toast(left && told.ok ? `${answer.text} ${WITHOUT_WHERE_WORDS}` : answer.text, answer.tone); |
| 120 | 120 | } |
| @@ -131,7 +131,7 @@ export function askForSomething(f: Session, ctx: Ctx, parent: () => Screen, repo | ||
| 131 | 131 | if (said === "") return SAY_SOMETHING_WORDS; |
| 132 | 132 | return (async () => { |
| 133 | 133 | 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()); | |
| 135 | 135 | ctx.toast(answer.text, answer.tone); |
| 136 | 136 | })(); |
| 137 | 137 | }, |
src/tui/screens/tell_here.ts +1 −1
| @@ -52,7 +52,7 @@ export function herePath(h: Here): string { | ||
| 52 | 52 | /** One tell from `h`: the answer, then the receipt, in one confirm line. */ |
| 53 | 53 | export async function tellHereNow(f: Pick<Session, "app" | "user">, ctx: Pick<Ctx, "toast">, h: Here, said: string, send: Sender = sendTell): Promise<void> { |
| 54 | 54 | 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()); | |
| 56 | 56 | // The receipt leads: a long answer is cut to the toast's width, the number must not be. |
| 57 | 57 | const lead = told.ok ? `Told from ${hereWords(h)} — receipt: issue #${told.value.issue.number}. ` : ""; |
| 58 | 58 | ctx.toast(`${lead}${answer.text}`, answer.tone); |
src/tui/ssh-tell.ts +3 −3
| @@ -90,7 +90,7 @@ async function told( | ||
| 90 | 90 | if (repo === undefined) return refuse(session, NO_CREW_WORDS); |
| 91 | 91 | const sentence = named?.words ?? said; |
| 92 | 92 | const result = await tell(app, user, repo, sentence, 1, from, from !== null); |
| 93 | const answer = tellAnswer(result); | |
| 93 | const answer = tellAnswer(result, sentence.trim()); | |
| 94 | 94 | if (!result.ok) return refuse(session, answer.text); |
| 95 | 95 | const base = app.config.url ?? `http://localhost:${app.config.port ?? 3000}`; |
| 96 | 96 | // 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 | ||
| 133 | 133 | const first = await firstAsk(app, user, said, crewCanRun(app)); |
| 134 | 134 | if (!first.ok) return refuse(session, first.error.words); |
| 135 | 135 | 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); | |
| 137 | 137 | const base = app.config.url ?? `http://localhost:${app.config.port ?? 3000}`; |
| 138 | 138 | 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}`, | |
| 140 | 140 | ); |
| 141 | 141 | session.exit(0); |
| 142 | 142 | } |
src/web/studio/actions.ts +6 −11
| @@ -14,8 +14,8 @@ 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 { 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"; | |
| 19 | 19 | import { TAKEN_BACK_WORDS, TOO_LATE_WORDS, tellUndoable, undoTell } from "../../actions/tell_undo.ts"; |
| 20 | 20 | import { contextNote, whereTold } from "../../actions/tell_context.ts"; |
| 21 | 21 | import { refusalWords } from "../../actions/tell_answer.ts"; |
| @@ -78,7 +78,7 @@ async function tellFrom( | ||
| 78 | 78 | tone: "danger", |
| 79 | 79 | message: SAY_SOMETHING_WORDS, |
| 80 | 80 | }); |
| 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) }); | |
| 82 | 82 | return toldAnswer(ctx, repo, form, back, from, await tell(ctx.app, ctx.auth.user, repo, text, 1, from), onTold); |
| 83 | 83 | } |
| 84 | 84 | |
| @@ -95,15 +95,10 @@ function toldAnswer( | ||
| 95 | 95 | subject = "", |
| 96 | 96 | ): Promise<Response> | Response { |
| 97 | 97 | 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 | }); | |
| 103 | 98 | if (!told.ok) |
| 104 | 99 | return flashOrJson(ctx, back, { |
| 105 | 100 | tone: "danger", |
| 106 | message: refusalWords(told.error), | |
| 101 | message: refusalWords(told.error, field(form, "text").trim()), | |
| 107 | 102 | }); |
| 108 | 103 | onTold(); |
| 109 | 104 | const { routed } = told.value; |
| @@ -183,12 +178,12 @@ async function tellFromPage(ctx: Ctx, repo: Repo, form: Form): Promise<Response> | ||
| 183 | 178 | const back = `${repoBase(repo)}/tell?${keep}`; |
| 184 | 179 | const text = field(form, "text").trim(); |
| 185 | 180 | 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) }); | |
| 187 | 182 | const told = await tell(ctx.app, ctx.auth.user, repo, `${text}${contextNote(where, { preview: true, app: repo.name })}`); |
| 188 | 183 | if (!told.ok) |
| 189 | 184 | return flashTo(ctx, back, { |
| 190 | 185 | tone: "danger", |
| 191 | message: refusalWords(told.error), | |
| 186 | message: refusalWords(told.error, text), | |
| 192 | 187 | }); |
| 193 | 188 | const issue = `${repoBase(repo)}/issues/${told.value.issue.number}`; |
| 194 | 189 | return page({ |
test/app-answers.test.ts +2 −2
| @@ -9,7 +9,7 @@ import { mkdtemp, rm } from "node:fs/promises"; | ||
| 9 | 9 | import { tmpdir } from "node:os"; |
| 10 | 10 | import { join } from "node:path"; |
| 11 | 11 | 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"; | |
| 13 | 13 | import { addToCrew, createAgent } from "../src/actions/crew.ts"; |
| 14 | 14 | import { commitToBranch, createRepo } from "../src/actions/repos.ts"; |
| 15 | 15 | import { createApp, type App } from "../src/app.ts"; |
| @@ -156,7 +156,7 @@ describe("the crew's answer under the tell box", () => { | ||
| 156 | 156 | const long = await tell(alice, "x".repeat(70_000)); |
| 157 | 157 | const flash = long.headers.getSetCookie().map((c) => c.split(";")[0]).join("; "); |
| 158 | 158 | 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.`); | |
| 160 | 160 | expect(listIssues(app.db, repo.id, { state: "all", limit: 50 }).length).toBe(before); |
| 161 | 161 | }); |
| 162 | 162 |
test/first-ask-refusals.test.ts +2 −2
| @@ -16,7 +16,7 @@ import { NEW_APP_ERRORS } from "../src/actions/apps.ts"; | ||
| 16 | 16 | import { deriveAppName } from "../src/web/pages/apps-name.ts"; |
| 17 | 17 | import { listReposOwnedBy } from "../src/core/repos.ts"; |
| 18 | 18 | 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"; | |
| 20 | 20 | import { quietLogs } from "./helpers/globals.ts"; |
| 21 | 21 | |
| 22 | 22 | quietLogs(); |
| @@ -54,7 +54,7 @@ test("too long, nobody signed in and a bad from each leave one row", async () => | ||
| 54 | 54 | const long = "x".repeat(MAX_BODY + 1); |
| 55 | 55 | const a = await firstAsk(app, maria, long, false); |
| 56 | 56 | 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.`); | |
| 58 | 58 | await firstAsk(app, undefined, "a menu page", false); |
| 59 | 59 | await firstAsk(app, maria, "a menu page", false, "not-a-from-value-\u0000"); |
| 60 | 60 | const rows = listRefusals(app.db, 10, Date.now()); |
test/mcp-tell.test.ts +11 −9
| @@ -2,6 +2,7 @@ | ||
| 2 | 2 | * `tell` refuses in the feed composer's words: one function (`refusalWords`) |
| 3 | 3 | * speaks for the page, the terminal and the MCP. |
| 4 | 4 | */ |
| 5 | import { tellTooLongWords } from "../src/actions/tell_from.ts"; | |
| 5 | 6 | import { afterAll, beforeAll, describe, expect, test } from "bun:test"; |
| 6 | 7 | import { mkdtemp, rm } from "node:fs/promises"; |
| 7 | 8 | import { tmpdir } from "node:os"; |
| @@ -79,9 +80,10 @@ describe("MCP tell refusals", () => { | ||
| 79 | 80 | }); |
| 80 | 81 | |
| 81 | 82 | 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 }); | |
| 83 | 85 | 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); | |
| 85 | 87 | }); |
| 86 | 88 | |
| 87 | 89 | /** The feed composer's own action (the studio's POST /:owner/:name/tell), asked for JSON. */ |
| @@ -99,8 +101,8 @@ describe("MCP tell refusals", () => { | ||
| 99 | 101 | test("the composer and the MCP refuse the same input in the same words", async () => { |
| 100 | 102 | const long = "x".repeat(7999) + "\n".repeat(3) + "y".repeat(60_000); |
| 101 | 103 | for (const [text, said] of [ |
| 102 | [" ", refusalWords("empty")], | |
| 103 | [long, refusalWords("body_too_long")], | |
| 104 | [" ", refusalWords("empty", "")], | |
| 105 | [long, tellTooLongWords(long)], | |
| 104 | 106 | ] as const) { |
| 105 | 107 | const web = await composer(text); |
| 106 | 108 | expect(web).toBe(said); |
| @@ -109,7 +111,7 @@ describe("MCP tell refusals", () => { | ||
| 109 | 111 | app.db.query("UPDATE email_check SET verified_at = NULL").run(); |
| 110 | 112 | try { |
| 111 | 113 | const web = await composer("hello"); |
| 112 | expect(web).toBe(refusalWords("unverified")); | |
| 114 | expect(web).toBe(refusalWords("unverified", "")); | |
| 113 | 115 | const mcp = await call({ repo: "alice/notes", text: "hello" }); |
| 114 | 116 | expect(mcp.error).toBe(true); |
| 115 | 117 | expect(mcp.text).toContain(web); |
| @@ -119,9 +121,9 @@ describe("MCP tell refusals", () => { | ||
| 119 | 121 | }); |
| 120 | 122 | |
| 121 | 123 | 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."); | |
| 126 | 128 | }); |
| 127 | 129 | }); |
test/ssh-tell.test.ts +3 −3
| @@ -10,7 +10,7 @@ import { createApp, type App } from "../src/app.ts"; | ||
| 10 | 10 | import { createRepo } from "../src/actions/repos.ts"; |
| 11 | 11 | import { SAY_SOMETHING_WORDS } from "../src/actions/tell_words.ts"; |
| 12 | 12 | 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"; | |
| 14 | 14 | import { refusalWords } from "../src/actions/tell_answer.ts"; |
| 15 | 15 | import { addKey, fingerprint, parseAuthorizedKey } from "../src/core/keys.ts"; |
| 16 | 16 | import { getRepo } from "../src/core/repos.ts"; |
| @@ -138,13 +138,13 @@ describe("ssh forge tell", () => { | ||
| 138 | 138 | const bare = await exec(KEY_A, "tell"); |
| 139 | 139 | expect(bare.err).toContain(SAY_SOMETHING_WORDS); |
| 140 | 140 | 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`]); | |
| 142 | 142 | for (const bad of ["tell a\x1b[2Jb", "tell a\nb", "tell a\x00b"]) { |
| 143 | 143 | const r = await exec(KEY_A, bad); |
| 144 | 144 | expect([r.code, r.err]).toEqual([1, `forge: ${CONTROL_WORDS}\r\n`]); |
| 145 | 145 | } |
| 146 | 146 | 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`]); | |
| 148 | 148 | expect(issues().length).toBe(1); |
| 149 | 149 | }); |
| 150 | 150 |
test/tell-limit-doors.test.ts +41
| @@ -109,3 +109,44 @@ test("every tell box says the limit in one line", async () => { | ||
| 109 | 109 | if (page.includes('name="text"')) expect(page).toContain(TELL_LIMIT_WORDS); |
| 110 | 110 | } |
| 111 | 111 | }); |
| 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", () => { | ||
| 118 | 118 | app.db.query("UPDATE email_check SET verified_at = NULL").run(); |
| 119 | 119 | try { |
| 120 | 120 | const seen = await drive(alice, ["t", ..."Unseen.", "\r"]); |
| 121 | expect(seen.text).toContain(refusalWords("unverified")); | |
| 121 | expect(seen.text).toContain(refusalWords("unverified", "")); | |
| 122 | 122 | } finally { |
| 123 | 123 | proveAll(app); |
| 124 | 124 | } |
test/tui-tell.test.ts +5 −4
| @@ -12,7 +12,8 @@ import { createApp, type App } from "../src/app.ts"; | ||
| 12 | 12 | import { listIssues, MAX_BODY } from "../src/core/issues.ts"; |
| 13 | 13 | import { createUser, type User } from "../src/core/users.ts"; |
| 14 | 14 | 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"; | |
| 16 | 17 | import { createForgeApp } from "../src/tui/forge.ts"; |
| 17 | 18 | import { repoScreen } from "../src/tui/screens/repo.ts"; |
| 18 | 19 | import { local } from "../src/tui/screens/where.ts"; |
| @@ -139,7 +140,7 @@ describe("tell the crew in the terminal", () => { | ||
| 139 | 140 | assigned: false, |
| 140 | 141 | routed: { builder: { user: { username: "mason" } }, size: "small", kind: "fix", by: "rule", ms: 1 }, |
| 141 | 142 | } as unknown as Told; |
| 142 | const answer = tellAnswer({ ok: true, value }); | |
| 143 | const answer = tellAnswer({ ok: true, value }, ""); | |
| 143 | 144 | expect(answer.text).toBe(toldWords(value)); |
| 144 | 145 | expect(answer.text).toContain("Opened as issue #7, but mason could not take it."); |
| 145 | 146 | expect(answer.text).not.toContain("is on it"); |
| @@ -147,10 +148,10 @@ describe("tell the crew in the terminal", () => { | ||
| 147 | 148 | }); |
| 148 | 149 | |
| 149 | 150 | 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", "")); | |
| 151 | 152 | }); |
| 152 | 153 | |
| 153 | 154 | 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.`); | |
| 155 | 156 | }); |
| 156 | 157 | }); |
Second import from ./tell_from.ts:
parseFromis already imported from it a line above. Merge them into one import.