fix: ack Feishu card actions before interrupt work

This commit is contained in:
2026-07-09 19:26:57 +08:00
parent d01ea0e1cb
commit f260195439
4 changed files with 206 additions and 29 deletions
+28
View File
@@ -618,6 +618,34 @@ describe("trigger full lifecycle (integration)", () => {
expect(rt.sentPatches.some((card) => cardHasInterruptedFooter(card))).toBe(true);
});
it("sends a fallback interrupt notice when the final card patch fails", async () => {
await seedProject("proj-int-patch-fail", "chat-int-patch-fail", { role: "MANAGE" });
runAgent = createHangingRunAgent();
const patch = vi.fn(async () => {
throw new Error("patch failed");
});
(rt.client as unknown as { im: { v1: { message: { patch: typeof patch } } } }).im.v1.message.patch = patch;
const trigger = makeTriggerHandler({ prisma, settings, logger: silentLogger, runAgent, messageBatcherOptions: { maxMessages: 1 } });
await trigger(makeEvent("chat-int-patch-fail", "@_user_1 写教案"), rt);
await vi.waitFor(async () => {
const runs = await prisma.agentRun.findMany();
expect(runs[0]?.status).toBe("ACTIVE");
});
const run = await prisma.agentRun.findFirst();
expect(run).not.toBeNull();
await trigger.onCardAction(makeInterruptEvent("chat-int-patch-fail", run!.id, "ou_test_user"), rt);
await vi.waitFor(async () => {
const runs = await prisma.agentRun.findMany();
expect(runs[0]?.status).toBe("CANCELED");
});
expect(patch).toHaveBeenCalled();
expect(rt.sentTexts).toContain("已中断当前运行。");
});
it("denies interrupt when the operator lacks agent.cancel permission", async () => {
// EDIT role can trigger but cannot cancel (agent.cancel requires MANAGE).
await seedProject("proj-int-deny", "chat-int-deny", { role: "EDIT" });