mirror of
https://github.com/moltbot/moltbot.git
synced 2026-04-26 07:57:40 +00:00
TUI: render sending and waiting indicators immediately
This commit is contained in:
@@ -2,6 +2,55 @@ import { describe, expect, it, vi } from "vitest";
|
||||
import { createCommandHandlers } from "./tui-command-handlers.js";
|
||||
|
||||
describe("tui command handlers", () => {
|
||||
it("renders the sending indicator before chat.send resolves", async () => {
|
||||
let resolveSend: ((value: { runId: string }) => void) | null = null;
|
||||
const sendChat = vi.fn(
|
||||
() =>
|
||||
new Promise<{ runId: string }>((resolve) => {
|
||||
resolveSend = resolve;
|
||||
}),
|
||||
);
|
||||
const addUser = vi.fn();
|
||||
const requestRender = vi.fn();
|
||||
const setActivityStatus = vi.fn();
|
||||
|
||||
const { handleCommand } = createCommandHandlers({
|
||||
client: { sendChat } as never,
|
||||
chatLog: { addUser, addSystem: vi.fn() } as never,
|
||||
tui: { requestRender } as never,
|
||||
opts: {},
|
||||
state: {
|
||||
currentSessionKey: "agent:main:main",
|
||||
activeChatRunId: null,
|
||||
sessionInfo: {},
|
||||
} as never,
|
||||
deliverDefault: false,
|
||||
openOverlay: vi.fn(),
|
||||
closeOverlay: vi.fn(),
|
||||
refreshSessionInfo: vi.fn(),
|
||||
loadHistory: vi.fn(),
|
||||
setSession: vi.fn(),
|
||||
refreshAgents: vi.fn(),
|
||||
abortActive: vi.fn(),
|
||||
setActivityStatus,
|
||||
formatSessionKey: vi.fn(),
|
||||
applySessionInfoFromPatch: vi.fn(),
|
||||
noteLocalRunId: vi.fn(),
|
||||
});
|
||||
|
||||
const pending = handleCommand("/context");
|
||||
await Promise.resolve();
|
||||
|
||||
expect(setActivityStatus).toHaveBeenCalledWith("sending");
|
||||
const sendingOrder = setActivityStatus.mock.invocationCallOrder[0] ?? 0;
|
||||
const renderOrders = requestRender.mock.invocationCallOrder;
|
||||
expect(renderOrders.some((order) => order > sendingOrder)).toBe(true);
|
||||
|
||||
resolveSend?.({ runId: "r1" });
|
||||
await pending;
|
||||
expect(setActivityStatus).toHaveBeenCalledWith("waiting");
|
||||
});
|
||||
|
||||
it("forwards unknown slash commands to the gateway", async () => {
|
||||
const sendChat = vi.fn().mockResolvedValue({ runId: "r1" });
|
||||
const addUser = vi.fn();
|
||||
|
||||
@@ -470,6 +470,7 @@ export function createCommandHandlers(context: CommandHandlerContext) {
|
||||
noteLocalRunId(runId);
|
||||
state.activeChatRunId = runId;
|
||||
setActivityStatus("sending");
|
||||
tui.requestRender();
|
||||
await client.sendChat({
|
||||
sessionKey: state.currentSessionKey,
|
||||
message: text,
|
||||
@@ -479,6 +480,7 @@ export function createCommandHandlers(context: CommandHandlerContext) {
|
||||
runId,
|
||||
});
|
||||
setActivityStatus("waiting");
|
||||
tui.requestRender();
|
||||
} catch (err) {
|
||||
if (state.activeChatRunId) {
|
||||
forgetLocalRunId?.(state.activeChatRunId);
|
||||
@@ -486,8 +488,8 @@ export function createCommandHandlers(context: CommandHandlerContext) {
|
||||
state.activeChatRunId = null;
|
||||
chatLog.addSystem(`send failed: ${String(err)}`);
|
||||
setActivityStatus("error");
|
||||
tui.requestRender();
|
||||
}
|
||||
tui.requestRender();
|
||||
};
|
||||
|
||||
return {
|
||||
|
||||
Reference in New Issue
Block a user