TUI: type setSession test mocks

This commit is contained in:
Vincent Koc
2026-03-07 18:33:32 -08:00
parent 100da9f45c
commit 6cb889da8c

View File

@@ -3,18 +3,19 @@ import { createCommandHandlers } from "./tui-command-handlers.js";
type LoadHistoryMock = ReturnType<typeof vi.fn> & (() => Promise<void>);
type SetActivityStatusMock = ReturnType<typeof vi.fn> & ((text: string) => void);
type SetSessionMock = ReturnType<typeof vi.fn> & ((key: string) => Promise<void>);
function createHarness(params?: {
sendChat?: ReturnType<typeof vi.fn>;
resetSession?: ReturnType<typeof vi.fn>;
setSession?: ReturnType<typeof vi.fn>;
setSession?: SetSessionMock;
loadHistory?: LoadHistoryMock;
setActivityStatus?: SetActivityStatusMock;
isConnected?: boolean;
}) {
const sendChat = params?.sendChat ?? vi.fn().mockResolvedValue({ runId: "r1" });
const resetSession = params?.resetSession ?? vi.fn().mockResolvedValue({ ok: true });
const setSession = params?.setSession ?? vi.fn().mockResolvedValue(undefined);
const setSession = params?.setSession ?? (vi.fn().mockResolvedValue(undefined) as SetSessionMock);
const addUser = vi.fn();
const addSystem = vi.fn();
const requestRender = vi.fn();
@@ -109,7 +110,7 @@ describe("tui command handlers", () => {
it("creates unique session for /new and resets shared session for /reset", async () => {
const loadHistory = vi.fn().mockResolvedValue(undefined);
const setSessionMock = vi.fn().mockResolvedValue(undefined);
const setSessionMock = vi.fn().mockResolvedValue(undefined) as SetSessionMock;
const { handleCommand, resetSession } = createHarness({
loadHistory,
setSession: setSessionMock,