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

An Instagram prompt keeps its first line: test/prompts.test.ts passes #11064

Merged opened this

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

Merged

scout/forge:scout/11052-an-instagram-prompt-keeps-its-first-line → main 2 commits fork

  • Merged. scout/11052-an-instagram-prompt-keeps-its-first-line was merged into main as 470b083.

Review

Sign in to review this change.
3 files changed +32 −5
src/actions/tell.ts +4 −1
@@ -35,6 +35,9 @@ export interface Told {
3535 readonly variantGroup: string | null;
3636 }
3737
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
3841 /** The most tries one tell may ask for at once. */
3942 export const VARIANTS_MAX = 4;
4043
@@ -100,7 +103,7 @@ export async function tell(
100103 }
101104 const firstLine = text.split(/\n/)[0]!.trim();
102105 const title =
103 firstLine.length <= 80 ? firstLine : `${firstLine.slice(0, 77).trimEnd()}…`;
106 firstLine.length <= TELL_TITLE_MAX ? firstLine : `${firstLine.slice(0, 77).trimEnd()}…`;
104107 // Several tries are several issues, each its own branch and pull, sharing
105108 // one group the pulls carry (`variant_group`).
106109 const many = variants > 1;
src/crew/prompts.ts +10 −4
@@ -14,7 +14,7 @@
1414 */
1515
1616 import type { App } from "../app.ts";
17 import { tell } from "../actions/tell.ts";
17 import { TELL_TITLE_MAX, tell } from "../actions/tell.ts";
1818 import {
1919 duePromptSources,
2020 getPromptSource,
@@ -144,11 +144,17 @@ function shortly(text: string): string {
144144 }
145145
146146 /**
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.
149152 */
150153 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();
152158 }
153159
154160 /**
test/prompts.test.ts +18
@@ -37,6 +37,7 @@ import {
3737 } from "../src/crew/instagram.ts";
3838 import {
3939 startPromptRoutine,
40 tellText,
4041 type PromptRoutineHandle,
4142 } from "../src/crew/prompts.ts";
4243 import { serve, type Servers } from "../src/http/server.ts";
@@ -90,6 +91,23 @@ describe("topComment", () => {
9091 });
9192 });
9293
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
93111 describe("the Instagram client", () => {
94112 /** A fetch that answers from a script and remembers what it was asked. */
95113 const scripted = (

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs