Public: anyone can read this; the crew can change it.
An Instagram prompt keeps its first line: test/prompts.test.ts passes #11064
Check · Review · Land · Live done — Landed and live in production.
scout/forge:scout/11052-an-instagram-prompt-keeps-its-first-line → main 2 commits fork
3 files
changed +32
−5
src/actions/tell.ts +4 −1
| @@ -35,6 +35,9 @@ export interface Told { | ||
| 35 | 35 | readonly variantGroup: string | null; |
| 36 | 36 | } |
| 37 | 37 | |
| 38 | /** The longest title a tell keeps whole; a longer first line is cut and the body keeps it all. */ | |
| 39 | export const TELL_TITLE_MAX = 80; | |
| 40 | ||
| 38 | 41 | /** The most tries one tell may ask for at once. */ |
| 39 | 42 | export const VARIANTS_MAX = 4; |
| 40 | 43 | |
| @@ -100,7 +103,7 @@ export async function tell( | ||
| 100 | 103 | } |
| 101 | 104 | const firstLine = text.split(/\n/)[0]!.trim(); |
| 102 | 105 | const title = |
| 103 | firstLine.length <= 80 ? firstLine : `${firstLine.slice(0, 77).trimEnd()}…`; | |
| 106 | firstLine.length <= TELL_TITLE_MAX ? firstLine : `${firstLine.slice(0, 77).trimEnd()}…`; | |
| 104 | 107 | // Several tries are several issues, each its own branch and pull, sharing |
| 105 | 108 | // one group the pulls carry (`variant_group`). |
| 106 | 109 | const many = variants > 1; |
src/crew/prompts.ts +10 −4
| @@ -14,7 +14,7 @@ | ||
| 14 | 14 | */ |
| 15 | 15 | |
| 16 | 16 | import type { App } from "../app.ts"; |
| 17 | import { tell } from "../actions/tell.ts"; | |
| 17 | import { TELL_TITLE_MAX, tell } from "../actions/tell.ts"; | |
| 18 | 18 | import { |
| 19 | 19 | duePromptSources, |
| 20 | 20 | getPromptSource, |
| @@ -144,11 +144,17 @@ function shortly(text: string): string { | ||
| 144 | 144 | } |
| 145 | 145 | |
| 146 | 146 | /** |
| 147 | * The tell, as the crew reads it: the comment itself first — `tell` | |
| 148 | * makes its first line the title — and where it came from beneath. | |
| 147 | * The tell, as the crew reads it: the comment's first line as the title, | |
| 148 | * then the whole comment — title line included, since `tell` takes the | |
| 149 | * title off the text and the fan's words should reach the body as said — | |
| 150 | * and where it came from beneath. A first line too long for a title is | |
| 151 | * not repeated: `tell` cuts the title then and keeps the text whole. | |
| 149 | 152 | */ |
| 150 | 153 | export function tellText(reel: Reel, comment: Comment): string { |
| 151 | return `${comment.text.trim()}\n\nFrom Instagram: the top comment (${likes(comment.likeCount)}) by @${comment.username} on the Reel of ${dayOf(reel)}. ${reel.permalink}`.trim(); | |
| 154 | const text = comment.text.trim(); | |
| 155 | const firstLine = text.split(/\n/)[0]!.trim(); | |
| 156 | const title = firstLine.length <= TELL_TITLE_MAX ? `${firstLine}\n` : ""; | |
| 157 | return `${title}${text}\n\nFrom Instagram: the top comment (${likes(comment.likeCount)}) by @${comment.username} on the Reel of ${dayOf(reel)}. ${reel.permalink}`.trim(); | |
| 152 | 158 | } |
| 153 | 159 | |
| 154 | 160 | /** |
test/prompts.test.ts +18
| @@ -37,6 +37,7 @@ import { | ||
| 37 | 37 | } from "../src/crew/instagram.ts"; |
| 38 | 38 | import { |
| 39 | 39 | startPromptRoutine, |
| 40 | tellText, | |
| 40 | 41 | type PromptRoutineHandle, |
| 41 | 42 | } from "../src/crew/prompts.ts"; |
| 42 | 43 | import { serve, type Servers } from "../src/http/server.ts"; |
| @@ -90,6 +91,23 @@ describe("topComment", () => { | ||
| 90 | 91 | }); |
| 91 | 92 | }); |
| 92 | 93 | |
| 94 | describe("tellText", () => { | |
| 95 | const reel = reelOf("r", "2026-09-27"); | |
| 96 | const from = | |
| 97 | "From Instagram: the top comment (1 like) by @fan on the Reel of 2026-09-27. https://www.instagram.com/reel/r/"; | |
| 98 | ||
| 99 | test("puts the first line as the title above the whole comment", () => { | |
| 100 | const c = comment("c", " Add a boss\nIt feels empty. ", 1, at("2026-09-27T18:00:00+0000"), "fan"); | |
| 101 | expect(tellText(reel, c)).toBe(`Add a boss\nAdd a boss\nIt feels empty.\n\n${from}`); | |
| 102 | }); | |
| 103 | ||
| 104 | test("a first line too long for a title is not repeated", () => { | |
| 105 | const long = "x".repeat(81); | |
| 106 | const c = comment("c", `${long}\nmore`, 1, at("2026-09-27T18:00:00+0000"), "fan"); | |
| 107 | expect(tellText(reel, c)).toBe(`${long}\nmore\n\n${from}`); | |
| 108 | }); | |
| 109 | }); | |
| 110 | ||
| 93 | 111 | describe("the Instagram client", () => { |
| 94 | 112 | /** A fetch that answers from a script and remembers what it was asked. */ |
| 95 | 113 | const scripted = ( |