























@@ -36,6 +36,16 @@ function expectSendChatFields(
3636}
3737}
383839+type MockWithCalls = { mock: { calls: unknown[][] } };
40+41+function firstMockArg(mock: MockWithCalls, label: string) {
42+const call = mock.mock.calls.at(0);
43+if (!call) {
44+throw new Error(`expected ${label} call`);
45+}
46+return call[0];
47+}
48+3949function createHarness(params?: {
4050sendChat?: ReturnType<typeof vi.fn>;
4151getGatewayStatus?: ReturnType<typeof vi.fn>;
@@ -245,7 +255,7 @@ describe("tui command handlers", () => {
245255const { handleCommand, sendChat, openOverlay, closeOverlay } = createHarness();
246256247257await handleCommand("/context");
248-const selector = openOverlay.mock.calls[0]?.[0] as SelectableOverlay | undefined;
258+const selector = firstMockArg(openOverlay, "openOverlay") as SelectableOverlay;
249259selector?.onSelect?.({ value: "detail", label: "detail" });
250260await flushAsyncSelect();
251261@@ -349,7 +359,7 @@ describe("tui command handlers", () => {
349359350360await handleCommand("hello");
351361352-const sentRunId = (sendChat.mock.calls[0]?.[0] as { runId: string }).runId;
362+const sentRunId = (firstMockArg(sendChat, "sendChat") as { runId: string }).runId;
353363expect(typeof sentRunId).toBe("string");
354364expect(sentRunId.length).toBeGreaterThan(0);
355365expect(state.activeChatRunId).toBeNull();
@@ -413,7 +423,7 @@ describe("tui command handlers", () => {
413423414424// /new creates a unique session key (isolates TUI client) (#39217)
415425expect(setSessionMock).toHaveBeenCalledTimes(1);
416-const newSessionKey = setSessionMock.mock.calls[0]?.[0] as string | undefined;
426+const newSessionKey = firstMockArg(setSessionMock, "setSession") as string | undefined;
417427if (!newSessionKey) {
418428throw new Error("expected /new to set a TUI session key");
419429}
@@ -561,7 +571,7 @@ describe("tui command handlers", () => {
561571562572await handleCommand("/model");
563573564-const selector = openOverlay.mock.calls[0]?.[0] as SelectableOverlay | undefined;
574+const selector = firstMockArg(openOverlay, "openOverlay") as SelectableOverlay;
565575expect(selector?.items?.[0]?.value).toBe("openrouter/auto");
566576expect(selector?.items?.[0]?.label).toBe("openrouter/auto");
567577此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。