
























@@ -427,6 +427,110 @@ describe("handleSendChat", () => {
427427vi.unstubAllGlobals();
428428});
429429430+it("cancels button-triggered /new resets when confirmation is declined", async () => {
431+const confirm = vi.fn(() => false);
432+vi.stubGlobal("confirm", confirm);
433+const request = vi.fn(async (method: string) => {
434+throw new Error(`Unexpected request: ${method}`);
435+});
436+const host = makeHost({
437+client: { request } as unknown as ChatHost["client"],
438+chatMessage: "keep this draft",
439+sessionKey: "agent:main",
440+});
441+442+await handleSendChat(host, "/new", { confirmReset: true, restoreDraft: true });
443+444+expect(confirm).toHaveBeenCalledWith("Start a new session? This will reset the current chat.");
445+expect(request).not.toHaveBeenCalled();
446+expect(host.chatMessage).toBe("keep this draft");
447+expect(host.chatMessages).toEqual([]);
448+expect(host.chatRunId).toBeNull();
449+expect(host.refreshSessionsAfterChat.size).toBe(0);
450+});
451+452+it("cancels button-triggered /new resets when confirmation is unavailable", async () => {
453+vi.stubGlobal("confirm", undefined);
454+const request = vi.fn(async (method: string) => {
455+throw new Error(`Unexpected request: ${method}`);
456+});
457+const host = makeHost({
458+client: { request } as unknown as ChatHost["client"],
459+chatMessage: "keep this draft",
460+sessionKey: "agent:main",
461+});
462+463+await handleSendChat(host, "/new", { confirmReset: true, restoreDraft: true });
464+465+expect(request).not.toHaveBeenCalled();
466+expect(host.chatMessage).toBe("keep this draft");
467+expect(host.chatMessages).toEqual([]);
468+expect(host.chatRunId).toBeNull();
469+expect(host.refreshSessionsAfterChat.size).toBe(0);
470+});
471+472+it("sends button-triggered /new resets after confirmation", async () => {
473+const confirm = vi.fn(() => true);
474+vi.stubGlobal("confirm", confirm);
475+const request = vi.fn(async (method: string) => {
476+if (method === "chat.send") {
477+return { status: "started" };
478+}
479+throw new Error(`Unexpected request: ${method}`);
480+});
481+const host = makeHost({
482+client: { request } as unknown as ChatHost["client"],
483+chatMessage: "restore me",
484+sessionKey: "agent:main",
485+});
486+487+await handleSendChat(host, "/new", { confirmReset: true, restoreDraft: true });
488+489+expect(confirm).toHaveBeenCalledTimes(1);
490+expect(request).toHaveBeenCalledWith(
491+"chat.send",
492+expect.objectContaining({
493+sessionKey: "agent:main",
494+message: "/new",
495+deliver: false,
496+idempotencyKey: expect.any(String),
497+}),
498+);
499+expect(host.chatMessage).toBe("restore me");
500+expect(host.refreshSessionsAfterChat).toContain(host.chatRunId);
501+});
502+503+it.each(["/new", "/reset"])(
504+"preserves typed %s command dispatch without confirmation",
505+async (command) => {
506+const confirm = vi.fn(() => false);
507+vi.stubGlobal("confirm", confirm);
508+const request = vi.fn(async (method: string) => {
509+if (method === "chat.send") {
510+return { status: "started" };
511+}
512+throw new Error(`Unexpected request: ${method}`);
513+});
514+const host = makeHost({
515+client: { request } as unknown as ChatHost["client"],
516+chatMessage: command,
517+sessionKey: "agent:main",
518+});
519+520+await handleSendChat(host);
521+522+expect(confirm).not.toHaveBeenCalled();
523+expect(request).toHaveBeenCalledWith(
524+"chat.send",
525+expect.objectContaining({
526+sessionKey: "agent:main",
527+message: command,
528+}),
529+);
530+expect(host.chatMessage).toBe("");
531+},
532+);
533+430534it("keeps slash-command model changes in sync with the chat header cache", async () => {
431535vi.stubGlobal(
432536"fetch",
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。