






















@@ -18,6 +18,24 @@ async function flushAsyncSelect() {
1818await new Promise<void>((resolve) => setImmediate(resolve));
1919}
202021+function expectSendChatFields(
22+sendChat: ReturnType<typeof vi.fn>,
23+expected: { message: string; sessionId?: string; sessionKey?: string },
24+) {
25+const call = sendChat.mock.calls.at(-1);
26+if (!call) {
27+throw new Error("expected gateway sendChat call");
28+}
29+const payload = call[0] as { message?: unknown; sessionId?: unknown; sessionKey?: unknown };
30+expect(payload.message).toBe(expected.message);
31+if (expected.sessionId !== undefined) {
32+expect(payload.sessionId).toBe(expected.sessionId);
33+}
34+if (expected.sessionKey !== undefined) {
35+expect(payload.sessionKey).toBe(expected.sessionKey);
36+}
37+}
38+2139function createHarness(params?: {
2240sendChat?: ReturnType<typeof vi.fn>;
2341getGatewayStatus?: ReturnType<typeof vi.fn>;
@@ -193,12 +211,10 @@ describe("tui command handlers", () => {
193211194212expect(addSystem).not.toHaveBeenCalled();
195213expect(addUser).toHaveBeenCalledWith("/unregistered-command");
196-expect(sendChat).toHaveBeenCalledWith(
197-expect.objectContaining({
198-sessionKey: "agent:main:main",
199-message: "/unregistered-command",
200-}),
201-);
214+expectSendChatFields(sendChat, {
215+sessionKey: "agent:main:main",
216+message: "/unregistered-command",
217+});
202218expect(requestRender).toHaveBeenCalled();
203219});
204220@@ -209,13 +225,11 @@ describe("tui command handlers", () => {
209225210226await handleCommand("/status");
211227212-expect(sendChat).toHaveBeenCalledWith(
213-expect.objectContaining({
214-sessionKey: "agent:main:main",
215-sessionId: "session-before-relaunch",
216-message: "/status",
217-}),
218-);
228+expectSendChatFields(sendChat, {
229+sessionKey: "agent:main:main",
230+sessionId: "session-before-relaunch",
231+message: "/status",
232+});
219233});
220234221235it("opens a context mode selector for /context without sending immediately", async () => {
@@ -235,12 +249,10 @@ describe("tui command handlers", () => {
235249selector?.onSelect?.({ value: "detail", label: "detail" });
236250await flushAsyncSelect();
237251238-expect(sendChat).toHaveBeenCalledWith(
239-expect.objectContaining({
240-sessionKey: "agent:main:main",
241-message: "/context detail",
242-}),
243-);
252+expectSendChatFields(sendChat, {
253+sessionKey: "agent:main:main",
254+message: "/context detail",
255+});
244256expect(closeOverlay).toHaveBeenCalledTimes(1);
245257});
246258@@ -250,12 +262,10 @@ describe("tui command handlers", () => {
250262await handleCommand("/context list");
251263252264expect(openOverlay).not.toHaveBeenCalled();
253-expect(sendChat).toHaveBeenCalledWith(
254-expect.objectContaining({
255-sessionKey: "agent:main:main",
256-message: "/context list",
257-}),
258-);
265+expectSendChatFields(sendChat, {
266+sessionKey: "agent:main:main",
267+message: "/context list",
268+});
259269});
260270261271it("forwards /context help directly", async () => {
@@ -264,12 +274,10 @@ describe("tui command handlers", () => {
264274await handleCommand("/context help");
265275266276expect(openOverlay).not.toHaveBeenCalled();
267-expect(sendChat).toHaveBeenCalledWith(
268-expect.objectContaining({
269-sessionKey: "agent:main:main",
270-message: "/context help",
271-}),
272-);
277+expectSendChatFields(sendChat, {
278+sessionKey: "agent:main:main",
279+message: "/context help",
280+});
273281});
274282275283it("forwards /status to the shared gateway command path", async () => {
@@ -279,12 +287,10 @@ describe("tui command handlers", () => {
279287280288expect(addSystem).not.toHaveBeenCalled();
281289expect(addUser).toHaveBeenCalledWith("/status");
282-expect(sendChat).toHaveBeenCalledWith(
283-expect.objectContaining({
284-sessionKey: "agent:main:main",
285-message: "/status",
286-}),
287-);
290+expectSendChatFields(sendChat, {
291+sessionKey: "agent:main:main",
292+message: "/status",
293+});
288294});
289295290296it("keeps gateway diagnostics on /gateway-status", async () => {
@@ -376,11 +382,7 @@ describe("tui command handlers", () => {
376382expect(state.activeChatRunId).toBe("run-main");
377383expect(setActivityStatus).not.toHaveBeenCalledWith("sending");
378384expect(setActivityStatus).not.toHaveBeenCalledWith("waiting");
379-expect(sendChat).toHaveBeenCalledWith(
380-expect.objectContaining({
381-message: "/btw what changed?",
382-}),
383-);
385+expectSendChatFields(sendChat, { message: "/btw what changed?" });
384386});
385387386388it("sends /side without hijacking the active main run", async () => {
@@ -395,11 +397,7 @@ describe("tui command handlers", () => {
395397expect(noteLocalRunId).not.toHaveBeenCalled();
396398expect(noteLocalBtwRunId).toHaveBeenCalledTimes(1);
397399expect(state.activeChatRunId).toBe("run-main");
398-expect(sendChat).toHaveBeenCalledWith(
399-expect.objectContaining({
400-message: "/side what changed?",
401-}),
402-);
400+expectSendChatFields(sendChat, { message: "/side what changed?" });
403401});
404402405403it("creates unique session for /new and resets shared session for /reset", async () => {
@@ -559,10 +557,8 @@ describe("tui command handlers", () => {
559557await handleCommand("/model");
560558561559const selector = openOverlay.mock.calls[0]?.[0] as SelectableOverlay | undefined;
562-expect(selector?.items?.[0]).toMatchObject({
563-value: "openrouter/auto",
564-label: "openrouter/auto",
565-});
560+expect(selector?.items?.[0]?.value).toBe("openrouter/auto");
561+expect(selector?.items?.[0]?.label).toBe("openrouter/auto");
566562567563selector?.onSelect?.({ value: "openrouter/auto", label: "openrouter/auto" });
568564await flushAsyncSelect();
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。