fix(telegram): prevent stuck typing after tool runs

This commit is contained in:
Peter Steinberger
2026-01-06 18:56:40 +00:00
parent 72ab9f3f42
commit 31dbc62bdd
3 changed files with 44 additions and 1 deletions

View File

@@ -51,4 +51,28 @@ describe("typing controller", () => {
vi.advanceTimersByTime(2_000);
expect(onReplyStart).toHaveBeenCalledTimes(3);
});
it("does not restart typing after it has stopped", async () => {
vi.useFakeTimers();
const onReplyStart = vi.fn(async () => {});
const typing = createTypingController({
onReplyStart,
typingIntervalSeconds: 1,
typingTtlMs: 30_000,
});
await typing.startTypingLoop();
expect(onReplyStart).toHaveBeenCalledTimes(1);
typing.markRunComplete();
typing.markDispatchIdle();
vi.advanceTimersByTime(5_000);
expect(onReplyStart).toHaveBeenCalledTimes(1);
// Late callbacks should be ignored and must not restart the interval.
await typing.startTypingOnText("late tool result");
vi.advanceTimersByTime(5_000);
expect(onReplyStart).toHaveBeenCalledTimes(1);
});
});