mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-13 10:30:36 +00:00
refactor(tui): dedupe handlers and formatter test setup
This commit is contained in:
@@ -22,6 +22,17 @@ type MockChatLog = {
|
||||
};
|
||||
type MockTui = { requestRender: MockFn };
|
||||
|
||||
function createMockChatLog(): MockChatLog & HandlerChatLog {
|
||||
return {
|
||||
startTool: vi.fn(),
|
||||
updateToolResult: vi.fn(),
|
||||
addSystem: vi.fn(),
|
||||
updateAssistant: vi.fn(),
|
||||
finalizeAssistant: vi.fn(),
|
||||
dropAssistant: vi.fn(),
|
||||
} as unknown as MockChatLog & HandlerChatLog;
|
||||
}
|
||||
|
||||
describe("tui-event-handlers: handleAgentEvent", () => {
|
||||
const makeState = (overrides?: Partial<TuiStateAccess>): TuiStateAccess => ({
|
||||
agentDefaultId: "main",
|
||||
@@ -47,14 +58,7 @@ describe("tui-event-handlers: handleAgentEvent", () => {
|
||||
});
|
||||
|
||||
const makeContext = (state: TuiStateAccess) => {
|
||||
const chatLog = {
|
||||
startTool: vi.fn(),
|
||||
updateToolResult: vi.fn(),
|
||||
addSystem: vi.fn(),
|
||||
updateAssistant: vi.fn(),
|
||||
finalizeAssistant: vi.fn(),
|
||||
dropAssistant: vi.fn(),
|
||||
} as unknown as MockChatLog & HandlerChatLog;
|
||||
const chatLog = createMockChatLog();
|
||||
const tui = { requestRender: vi.fn() } as unknown as MockTui & HandlerTui;
|
||||
const setActivityStatus = vi.fn();
|
||||
const loadHistory = vi.fn();
|
||||
@@ -62,13 +66,9 @@ describe("tui-event-handlers: handleAgentEvent", () => {
|
||||
const noteLocalRunId = (runId: string) => {
|
||||
localRunIds.add(runId);
|
||||
};
|
||||
const forgetLocalRunId = (runId: string) => {
|
||||
localRunIds.delete(runId);
|
||||
};
|
||||
const isLocalRunId = (runId: string) => localRunIds.has(runId);
|
||||
const clearLocalRunIds = () => {
|
||||
localRunIds.clear();
|
||||
};
|
||||
const forgetLocalRunId = localRunIds.delete.bind(localRunIds);
|
||||
const isLocalRunId = localRunIds.has.bind(localRunIds);
|
||||
const clearLocalRunIds = localRunIds.clear.bind(localRunIds);
|
||||
|
||||
return {
|
||||
chatLog,
|
||||
@@ -148,14 +148,7 @@ describe("tui-event-handlers: handleAgentEvent", () => {
|
||||
});
|
||||
|
||||
it("processes lifecycle events when runId matches activeChatRunId", () => {
|
||||
const chatLog = {
|
||||
startTool: vi.fn(),
|
||||
updateToolResult: vi.fn(),
|
||||
addSystem: vi.fn(),
|
||||
updateAssistant: vi.fn(),
|
||||
finalizeAssistant: vi.fn(),
|
||||
dropAssistant: vi.fn(),
|
||||
} as unknown as HandlerChatLog;
|
||||
const chatLog = createMockChatLog();
|
||||
const { tui, setActivityStatus, handleAgentEvent } = createHandlersHarness({
|
||||
state: { activeChatRunId: "run-9" },
|
||||
chatLog,
|
||||
|
||||
Reference in New Issue
Block a user