feat: keep typing indicators alive during commands

This commit is contained in:
Peter Steinberger
2025-11-26 00:05:11 +01:00
parent 5b83d30887
commit d871dad85f
5 changed files with 104 additions and 17 deletions

View File

@@ -601,6 +601,49 @@ describe("config and templating", () => {
expect(secondArgv[secondArgv.length - 1]).toBe("[sys] next");
});
it("refreshes typing indicator while command runs", async () => {
vi.useFakeTimers();
const onReplyStart = vi.fn();
const runSpy = vi
.spyOn(index, "runCommandWithTimeout")
.mockImplementation(
() =>
new Promise((resolve) =>
setTimeout(
() =>
resolve({
stdout: "done\n",
stderr: "",
code: 0,
signal: null,
killed: false,
}),
35_000,
),
),
);
const cfg = {
inbound: {
reply: {
mode: "command" as const,
command: ["echo", "{{Body}}"],
typingIntervalSeconds: 10,
},
},
};
const promise = index.getReplyFromConfig(
{ Body: "hi", From: "+1", To: "+2" },
{ onReplyStart },
cfg,
runSpy,
);
await vi.advanceTimersByTimeAsync(35_000);
await promise;
expect(onReplyStart.mock.calls.length).toBeGreaterThanOrEqual(4);
vi.useRealTimers();
});
it("injects Claude output format + print flag when configured", async () => {
const runSpy = vi.spyOn(index, "runCommandWithTimeout").mockResolvedValue({
stdout: "ok",