fix: only inject interrupt recovery after real user interrupts (#936)
This commit is contained in:
@@ -2,7 +2,12 @@ import { describe, expect, test } from "bun:test";
|
||||
import type { Message } from "@letta-ai/letta-client/resources/agents/messages";
|
||||
import { createBuffers } from "../../cli/helpers/accumulator";
|
||||
import { backfillBuffers } from "../../cli/helpers/backfill";
|
||||
import { SYSTEM_REMINDER_CLOSE, SYSTEM_REMINDER_OPEN } from "../../constants";
|
||||
import {
|
||||
SYSTEM_ALERT_CLOSE,
|
||||
SYSTEM_ALERT_OPEN,
|
||||
SYSTEM_REMINDER_CLOSE,
|
||||
SYSTEM_REMINDER_OPEN,
|
||||
} from "../../constants";
|
||||
|
||||
function userMessage(
|
||||
id: string,
|
||||
@@ -65,4 +70,20 @@ describe("backfill system-reminder handling", () => {
|
||||
expect(buffers.byId.get("u3")).toBeUndefined();
|
||||
expect(buffers.order).toHaveLength(0);
|
||||
});
|
||||
|
||||
test("hides legacy system-alert blocks from backfill", () => {
|
||||
const buffers = createBuffers();
|
||||
const history = [
|
||||
userMessage(
|
||||
"u4",
|
||||
`${SYSTEM_ALERT_OPEN}The user interrupted the active stream.${SYSTEM_ALERT_CLOSE}\n\nhello :D`,
|
||||
),
|
||||
];
|
||||
|
||||
backfillBuffers(buffers, history);
|
||||
|
||||
const line = buffers.byId.get("u4");
|
||||
expect(line?.kind).toBe("user");
|
||||
expect(line && "text" in line ? line.text : "").toBe("hello :D");
|
||||
});
|
||||
});
|
||||
|
||||
21
src/tests/cli/interrupt-recovery-wiring.test.ts
Normal file
21
src/tests/cli/interrupt-recovery-wiring.test.ts
Normal file
@@ -0,0 +1,21 @@
|
||||
import { describe, expect, test } from "bun:test";
|
||||
import { readFileSync } from "node:fs";
|
||||
import { fileURLToPath } from "node:url";
|
||||
|
||||
describe("interrupt recovery alert wiring", () => {
|
||||
test("gates alert injection on explicit user interrupt state", () => {
|
||||
const appPath = fileURLToPath(
|
||||
new URL("../../cli/App.tsx", import.meta.url),
|
||||
);
|
||||
const source = readFileSync(appPath, "utf-8");
|
||||
|
||||
expect(source).toContain("pendingInterruptRecoveryConversationIdRef");
|
||||
expect(source).toContain("canInjectInterruptRecovery");
|
||||
expect(source).toContain(
|
||||
"pendingInterruptRecoveryConversationIdRef.current ===",
|
||||
);
|
||||
expect(source).toContain(
|
||||
"pendingInterruptRecoveryConversationIdRef.current = null;",
|
||||
);
|
||||
});
|
||||
});
|
||||
@@ -18,4 +18,13 @@ describe("splitSystemReminderBlocks", () => {
|
||||
expect(blocks.some((b) => b.text.includes("before"))).toBe(true);
|
||||
expect(blocks.some((b) => b.text.includes("after"))).toBe(true);
|
||||
});
|
||||
|
||||
test("detects legacy system-alert blocks as system context", () => {
|
||||
const blocks = splitSystemReminderBlocks(
|
||||
"before\n<system-alert>alert</system-alert>\nafter",
|
||||
);
|
||||
|
||||
expect(blocks.some((b) => b.isSystemReminder)).toBe(true);
|
||||
expect(blocks.some((b) => b.text.includes("<system-alert>"))).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user