Skip to content

Open-source Grok Bot alternative with a virtual machine that bots can use

fix(routines): keep the default line of a bare NEEDS INPUT when blank lines separate them

AdityaUmale04d3dcb0141d
diff --git a/server/automation-reports.test.ts b/server/automation-reports.test.ts
index 78f59972d5..a9bf03ef50 100644
--- a/server/automation-reports.test.ts
+++ b/server/automation-reports.test.ts
@@ -53,6 +53,9 @@ describe("routineRunNeedsReview", () => {
const bare = `${"Long report. ".repeat(300)}\nNEEDS INPUT:\ndefault: ${"wait ".repeat(500)}`;
expect(routineRunNeedsReview({ status: "completed", output: clipRunOutput(bare, 2_000) })).toBe(routineRunNeedsReview({ status: "completed" }, bare));
expect(routineRunNeedsReview({ status: "completed", output: clipRunOutput(bare, 2_000) })).toBe(true);
+ const spaced = `${"Long report. ".repeat(300)}\nNEEDS INPUT:\n${"\n".repeat(2_000)}default: ${"wait ".repeat(500)}`;
+ expect(routineRunNeedsReview({ status: "completed", output: clipRunOutput(spaced, 2_000) })).toBe(routineRunNeedsReview({ status: "completed" }, spaced));
+ expect(routineRunNeedsReview({ status: "completed", output: clipRunOutput(spaced, 2_000) })).toBe(true);
expect(routineRunNeedsReview({ status: "cancelled" })).toBe(false);
});
});
diff --git a/server/routine-lines.test.ts b/server/routine-lines.test.ts
index 81a3ebb06e..8713e4c37e 100644
--- a/server/routine-lines.test.ts
+++ b/server/routine-lines.test.ts
@@ -86,4 +86,10 @@ describe("clipRunOutput", () => {
expect(cut.length).toBe(2_000);
expect(cut.startsWith("NEEDS INPUT:\ndefault: wait")).toBe(true);
});
+
+ it("keeps the default line of a bare NEEDS INPUT line when blank lines separate them", () => {
+ const cut = clipRunOutput(`${long}\nNEEDS INPUT:\n${"\n".repeat(2_000)}default: ${"wait ".repeat(500)}`, 2_000);
+ expect(cut.length).toBe(2_000);
+ expect(cut.startsWith("NEEDS INPUT:\ndefault: wait")).toBe(true);
+ });
});
diff --git a/server/routine-lines.ts b/server/routine-lines.ts
index 445ecd9383..03cadf3a25 100644
--- a/server/routine-lines.ts
+++ b/server/routine-lines.ts
@@ -104,7 +104,8 @@ export function clipRunOutput(text: string, max: number): string {
if (tail.length > max) {
const question = lines[at]!.trim();
// A bare NEEDS INPUT: line asks through its default: line, so that line is kept (cut) with it.
- if (!question.replace(CLOSING_QUESTION, "").trim()) return `${tail.slice(0, max - 1)}…`;
+ // Blank lines between them say nothing, so they go first; otherwise they could push the default: line out.
+ if (!question.replace(CLOSING_QUESTION, "").trim()) return `${[question, ...after].join("\n").slice(0, max - 1)}…`;
return question.length <= max ? question : `${question.slice(0, max - 1)}…`;
}
const room = max - tail.length - 3;