






















@@ -1,5 +1,9 @@
11import { describe, expect, it, vi } from "vitest";
22import { createCommandHandlers } from "./tui-command-handlers.js";
3+import {
4+TUI_RECENT_SESSIONS_ACTIVE_MINUTES,
5+TUI_SESSION_PICKER_LIMIT,
6+} from "./tui-session-list-policy.js";
3748type LoadHistoryMock = ReturnType<typeof vi.fn> & (() => Promise<void>);
59type RunAuthFlow = NonNullable<Parameters<typeof createCommandHandlers>[0]["runAuthFlow"]>;
@@ -16,6 +20,7 @@ async function flushAsyncSelect() {
1620function createHarness(params?: {
1721sendChat?: ReturnType<typeof vi.fn>;
1822getGatewayStatus?: ReturnType<typeof vi.fn>;
23+listSessions?: ReturnType<typeof vi.fn>;
1924patchSession?: ReturnType<typeof vi.fn>;
2025resetSession?: ReturnType<typeof vi.fn>;
2126runAuthFlow?: RunAuthFlow;
@@ -32,6 +37,7 @@ function createHarness(params?: {
3237}) {
3338const sendChat = params?.sendChat ?? vi.fn().mockResolvedValue({ runId: "r1" });
3439const getGatewayStatus = params?.getGatewayStatus ?? vi.fn().mockResolvedValue({});
40+const listSessions = params?.listSessions ?? vi.fn().mockResolvedValue({ sessions: [] });
3541const patchSession = params?.patchSession ?? vi.fn().mockResolvedValue({});
3642const resetSession = params?.resetSession ?? vi.fn().mockResolvedValue({ ok: true });
3743const setSession = params?.setSession ?? (vi.fn().mockResolvedValue(undefined) as SetSessionMock);
@@ -64,8 +70,8 @@ function createHarness(params?: {
6470sessionInfo: {},
6571};
667267-const { handleCommand } = createCommandHandlers({
68-client: { sendChat, getGatewayStatus, patchSession, resetSession } as never,
73+const { handleCommand, openSessionSelector } = createCommandHandlers({
74+client: { sendChat, getGatewayStatus, listSessions, patchSession, resetSession } as never,
6975chatLog: { addUser, addSystem } as never,
7076tui: { requestRender } as never,
7177opts: params?.opts ?? {},
@@ -92,7 +98,9 @@ function createHarness(params?: {
9298return {
9399 handleCommand,
94100 getGatewayStatus,
101+ listSessions,
95102 sendChat,
103+ openSessionSelector,
96104 openOverlay,
97105 closeOverlay,
98106 patchSession,
@@ -114,6 +122,31 @@ function createHarness(params?: {
114122}
115123116124describe("tui command handlers", () => {
125+it("bounds session picker hydration to recent TUI sessions", async () => {
126+const listSessions = vi.fn().mockResolvedValue({
127+sessions: [
128+{
129+key: "agent:main:main",
130+displayName: "main",
131+updatedAt: Date.now(),
132+},
133+],
134+});
135+const { openSessionSelector } = createHarness({ listSessions });
136+137+await openSessionSelector();
138+139+expect(listSessions).toHaveBeenCalledWith({
140+limit: TUI_SESSION_PICKER_LIMIT,
141+activeMinutes: TUI_RECENT_SESSIONS_ACTIVE_MINUTES,
142+includeGlobal: false,
143+includeUnknown: false,
144+includeDerivedTitles: true,
145+includeLastMessage: true,
146+agentId: "main",
147+});
148+});
149+117150it("renders the sending indicator before chat.send resolves", async () => {
118151let resolveSend: (value: { runId: string }) => void = () => {
119152throw new Error("sendChat promise resolver was not initialized");
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。