From ca10d8f384704d5c1e66854f56495483aba5d10e Mon Sep 17 00:00:00 2001 From: Huarch Date: Fri, 25 Sep 2026 15:44:46 +0800 Subject: [PATCH] fix(chat): clarify approval mode and verify permission prompts --- src/components/chat/AgentComposer.tsx | 2 +- .../chat/AgentPermissionRequests.test.tsx | 47 +++++++++++++++++++ 2 files changed, 48 insertions(+), 1 deletion(-) create mode 100644 src/components/chat/AgentPermissionRequests.test.tsx diff --git a/src/components/chat/AgentComposer.tsx b/src/components/chat/AgentComposer.tsx index d89ebb0..6f8cebb 100644 --- a/src/components/chat/AgentComposer.tsx +++ b/src/components/chat/AgentComposer.tsx @@ -79,7 +79,7 @@ const approvalModeOptions: ReadonlyArray<{ { value: "always", label: "始终允许", - description: "除明确禁止项外自动放行", + description: "常规权限自动放行,敏感路径仍需确认", icon: WarningAmberRounded, }, ]; diff --git a/src/components/chat/AgentPermissionRequests.test.tsx b/src/components/chat/AgentPermissionRequests.test.tsx new file mode 100644 index 0000000..94ff6b2 --- /dev/null +++ b/src/components/chat/AgentPermissionRequests.test.tsx @@ -0,0 +1,47 @@ +import React from "react"; +import { fireEvent, render, screen } from "@testing-library/react"; +import { ThemeProvider, createTheme } from "@mui/material/styles"; + +import { PermissionRequestGroup } from "./AgentPermissionRequests"; + +jest.mock("framer-motion", () => ({ + AnimatePresence: ({ children }: { children: React.ReactNode }) => <>{children}, + motion: { + div: ({ children, ...props }: React.HTMLAttributes) => ( +
{children}
+ ), + }, +})); + +describe("PermissionRequestGroup", () => { + it("shows an external path approval request and forwards the user's decision", () => { + const onReply = jest.fn(); + render( + + + , + ); + + expect(screen.getByText("访问工作区外目录")).toBeInTheDocument(); + expect(screen.getByText("/app/private/report.json")).toBeInTheDocument(); + fireEvent.click(screen.getByRole("button", { name: "允许一次" })); + expect(onReply).toHaveBeenCalledWith("external-1", "once"); + fireEvent.click(screen.getByRole("button", { name: "保存授权" })); + expect(onReply).toHaveBeenCalledWith("external-1", "always"); + }); +});