| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943 |
- import {
- OFFICIAL_CUA_PERMISSION_RULE_TOOL_NAME,
- type ZCodePermissionRequest,
- type ZCodeProvider,
- } from "@zcode/shared";
- import { createElement } from "react";
- import type { ComponentType } from "react";
- import { renderToStaticMarkup } from "react-dom/server";
- import { describe, expect, it } from "vitest";
- import { PermissionDialog } from "../src/PermissionDialog.js";
- import { ZCodeIntlProvider } from "../src/i18n/IntlProvider.js";
- const WORKSPACE_PATH = "/Users/dev/ZCodeProject/demo";
- const SUBAGENT_ORIGIN = {
- kind: "subagent" as const,
- agentId: "general-purpose",
- agentType: "general-purpose",
- childSessionId: "sess-child",
- parentSessionId: "sess-parent",
- parentToolCallId: "tool-parent-agent",
- };
- function renderPermissionDialog(
- request: ZCodePermissionRequest,
- provider?: ZCodeProvider,
- extraProps: Record<string, unknown> = {},
- ) {
- const Dialog = PermissionDialog as ComponentType<Record<string, unknown>>;
- return renderToStaticMarkup(
- createElement(
- ZCodeIntlProvider,
- { initialLocale: "zh-CN" },
- createElement(Dialog, {
- request,
- onRespond: () => {},
- workspacePath: WORKSPACE_PATH,
- provider,
- ...extraProps,
- }),
- ),
- );
- }
- describe("PermissionDialog", () => {
- it("renders the optional feedback input only when V4 enables it", () => {
- const withoutFeedback = renderPermissionDialog({
- type: "permission_request",
- taskId: "task-no-feedback",
- traceId: "trace-no-feedback",
- requestId: "request-no-feedback",
- description: "Run ls",
- kind: "Bash",
- options: [
- {
- optionId: "deny",
- kind: "deny",
- name: "Deny",
- response: { decision: "deny" },
- },
- ],
- raw: { command: "ls" },
- });
- const withFeedback = renderPermissionDialog({
- type: "permission_request",
- taskId: "task-feedback",
- traceId: "trace-feedback",
- requestId: "request-feedback",
- description: "Run ls",
- kind: "Bash",
- freeText: true,
- options: [
- {
- optionId: "deny",
- kind: "deny",
- name: "Deny",
- response: { decision: "deny" },
- },
- ],
- raw: { command: "ls" },
- });
- expect(withoutFeedback).not.toContain("chat.permission.feedback.placeholder");
- expect(withFeedback).toContain("告诉模型接下来应该怎么做...");
- expect(withFeedback).toContain("<textarea");
- expect(withFeedback).toContain('wrap="soft"');
- expect(withFeedback).toContain("field-sizing-content");
- expect(withFeedback).toContain("max-h-[5lh]");
- expect(withFeedback).toContain("overflow-y-auto");
- expect(withFeedback).toContain("focus-visible:ring-0");
- expect(withFeedback).toContain('maxLength="4096"');
- });
- it("labels an authority-verified Computer Use project grant explicitly", () => {
- const html = renderPermissionDialog({
- type: "permission_request",
- taskId: "task-cua",
- traceId: "trace-cua",
- requestId: "request-cua",
- description: "Control TextEdit",
- kind: "mcp__computer-use__left_click",
- title: "Computer Use",
- options: [
- {
- optionId: "allow_project",
- kind: "allow_always",
- name: "Always allow Computer Use in this project",
- response: {
- decision: "allow",
- permissionUpdates: [
- {
- behavior: "allow",
- rules: [{ toolName: OFFICIAL_CUA_PERMISSION_RULE_TOOL_NAME }],
- type: "addRules",
- },
- ],
- },
- },
- ],
- raw: { rawInput: { app_ref: { bundle_id: "com.apple.TextEdit" } } },
- });
- expect(html).toContain("始终允许本项目中的电脑控制");
- expect(html).toContain('aria-label="始终允许本项目中的电脑控制"');
- expect(html).toContain('aria-label="确认"');
- expect(html).toContain("本项目后续官方电脑控制操作不再询问");
- expect(html).not.toContain("后续相同权限请求不再询问");
- });
- it("renders compound prefix scopes inline without an exact-command card", () => {
- const html = renderPermissionDialog({
- type: "permission_request",
- taskId: "task-1",
- traceId: "trace-1",
- requestId: "request-scopes",
- description: "Run commands",
- kind: "Bash",
- title: "Bash",
- options: [
- {
- optionId: "allow_project",
- kind: "allow_always",
- name: "Always allow in this project",
- response: {
- decision: "allow",
- permissionUpdates: [
- {
- behavior: "allow",
- rules: [
- { ruleContent: "pnpm run lint:*", toolName: "Bash" },
- { ruleContent: "rm -rf ./generated", toolName: "Bash" },
- ],
- type: "addRules",
- },
- ],
- },
- },
- ],
- raw: {
- rawInput: { command: "pnpm run lint --fix && rm -rf ./generated" },
- },
- });
- expect(html).toContain('data-permission-rule-scopes="true"');
- expect(html).toContain('data-permission-rule-prefixes="true"');
- expect(html).toContain('data-permission-option-kind="allowAlways"');
- expect(html).toContain('data-permission-rule-scope="prefix"');
- expect(html).not.toContain('data-permission-rule-scope="exact"');
- expect(html).not.toContain("命令前缀");
- expect(html).not.toContain("后续相同命令不再询问");
- expect(html).toContain("pnpm run lint …");
- expect(html).not.toContain("仅此命令");
- expect(html).toContain("rm -rf ./generated");
- expect(html).not.toContain("<input");
- });
- it("does not render exact permission rules inside the allow-always option", () => {
- const heredocBody = `HEREDOC_BODY_MUST_NOT_RENDER_${"x".repeat(1000)}`;
- const oversizedTail = `${"y".repeat(300)}OVERSIZED_TAIL_MUST_NOT_RENDER`;
- const html = renderPermissionDialog({
- type: "permission_request",
- taskId: "task-1",
- traceId: "trace-1",
- requestId: "request-long-exact",
- description: "Write generated files",
- kind: "Bash",
- title: "Bash",
- options: [
- {
- optionId: "allow_project",
- kind: "allow_always",
- name: "Always allow in this project",
- response: {
- decision: "allow",
- permissionUpdates: [
- {
- behavior: "allow",
- rules: [
- {
- ruleContent: `cat > /tmp/sun.html << 'EOF'\n${heredocBody}\nEOF`,
- toolName: "Bash",
- },
- {
- ruleContent: `python -c '${oversizedTail}'`,
- toolName: "Bash",
- },
- ],
- type: "addRules",
- },
- ],
- },
- },
- ],
- raw: { rawInput: { command: "write generated files" } },
- });
- expect(html).not.toContain('data-permission-rule-scopes="true"');
- expect(html).not.toContain('data-permission-rule-scope="exact"');
- expect(html).not.toContain("cat > /tmp/sun.html");
- expect(html).not.toContain("HEREDOC_BODY_MUST_NOT_RENDER");
- expect(html).not.toContain("OVERSIZED_TAIL_MUST_NOT_RENDER");
- expect(html).not.toContain("仅此命令");
- expect(html).toContain("后续相同命令不再询问");
- });
- it("wraps a long prefix in the allow-always description position", () => {
- const html = renderPermissionDialog({
- type: "permission_request",
- taskId: "task-1",
- traceId: "trace-1",
- requestId: "request-long-prefix",
- description: "Run command",
- kind: "Bash",
- title: "Bash",
- options: [
- {
- optionId: "allow_project",
- kind: "allow_always",
- name: "Always allow in this project",
- response: {
- decision: "allow",
- permissionUpdates: [
- {
- behavior: "allow",
- rules: [
- {
- ruleContent: `pnpm run ${"unbroken-prefix-".repeat(20)}:*`,
- toolName: "Bash",
- },
- ],
- type: "addRules",
- },
- ],
- },
- },
- ],
- raw: { rawInput: { command: "run long command" } },
- });
- expect(html).toContain('data-permission-rule-prefixes="true"');
- expect(html).toContain('data-permission-rule-scopes="true"');
- expect(html).toContain("basis-48");
- expect(html).toContain("whitespace-pre-wrap");
- expect(html).toContain("break-all");
- expect(html).toContain('data-permission-rule-scope-truncated="true"');
- expect(html).not.toContain("后续相同命令不再询问");
- });
- it("shows a subagent source tag for delegated permission requests only", () => {
- const baseRequest: ZCodePermissionRequest = {
- type: "permission_request",
- taskId: "task-1",
- traceId: "trace-1",
- requestId: "request-1",
- description: "Run command",
- kind: "Bash",
- title: "Bash",
- options: [
- {
- optionId: "allow",
- kind: "allow",
- name: "Allow",
- },
- ],
- raw: {
- toolName: "Bash",
- },
- };
- const mainHtml = renderPermissionDialog(baseRequest);
- const subagentHtml = renderPermissionDialog({
- ...baseRequest,
- origin: SUBAGENT_ORIGIN,
- });
- expect(mainHtml).not.toContain('data-interaction-origin-badge="subagent"');
- expect(subagentHtml).toContain('data-interaction-origin-badge="subagent"');
- expect(subagentHtml).toContain("子智能体");
- expect(subagentHtml).toContain("来自子智能体:general-purpose");
- });
- it("names the subagent in the source tag when the origin carries a description", () => {
- const html = renderPermissionDialog({
- type: "permission_request",
- taskId: "task-1",
- traceId: "trace-1",
- requestId: "request-1",
- description: "Run command",
- kind: "Bash",
- title: "Bash",
- options: [{ optionId: "allow", kind: "allow", name: "Allow" }],
- raw: { toolName: "Bash" },
- // 动态工作流子代理的 origin(docs/dynamic-workflow/launch.md「Permissions inside a run」)。
- origin: {
- ...SUBAGENT_ORIGIN,
- agentType: "zcode-workflow",
- description: "reviewer (agent#1@0)",
- },
- });
- expect(html).toContain('data-interaction-origin-badge="subagent"');
- expect(html).toContain("子智能体 · reviewer (agent#1@0)");
- // 截断时完整文本留在 tooltip 里,且仍带 agentType。
- expect(html).toContain("来自子智能体:zcode-workflow · reviewer (agent#1@0)");
- });
- it("renders a compact implementation plan placeholder for switch mode requests", () => {
- const html = renderPermissionDialog({
- type: "permission_request",
- taskId: "task-1",
- traceId: "trace-1",
- requestId: "request-1",
- description: "Ready to code?",
- kind: "switch_mode",
- title: "Ready to code?",
- options: [
- {
- optionId: "code",
- kind: "allow_always",
- name: "是,并自动接受后续操作",
- },
- ],
- raw: {},
- });
- expect(html).toContain("实施计划");
- expect(html).not.toContain("ToolCall");
- expect(html).not.toContain("Ready to code?");
- });
- it("renders a compact implementation plan placeholder for ExitPlanMode requests", () => {
- const html = renderPermissionDialog({
- type: "permission_request",
- taskId: "task-1",
- traceId: "trace-1",
- requestId: "request-1",
- description: "ExitPlanMode changes session mode after user plan approval",
- kind: "ExitPlanMode",
- title: "ExitPlanMode",
- options: [
- {
- optionId: "allow",
- kind: "allow",
- name: "Allow",
- },
- {
- optionId: "deny",
- kind: "deny",
- name: "Deny",
- },
- ],
- raw: {
- toolName: "ExitPlanMode",
- },
- });
- expect(html).toContain("实施计划");
- expect(html).not.toContain("ToolCall");
- expect(html).not.toContain("ExitPlanMode changes session mode");
- });
- it("prefers custom ZCode Agent option names over generic kind labels", () => {
- const html = renderPermissionDialog({
- type: "permission_request",
- taskId: "task-1",
- traceId: "trace-1",
- requestId: "request-1",
- description: "Ready to code?",
- kind: "switch_mode",
- title: "Ready to code?",
- options: [
- {
- optionId: "code",
- kind: "allow_always",
- name: "是,并自动接受后续操作",
- },
- {
- optionId: "ask",
- kind: "allow_always",
- name: "是,但高风险操作仍逐次确认",
- },
- {
- optionId: "reject",
- kind: "reject_once",
- name: "否,先继续整理计划",
- },
- ],
- raw: {},
- });
- expect(html).toContain("是,并自动接受后续操作");
- expect(html).toContain("是,但高风险操作仍逐次确认");
- expect(html).toContain("否,先继续整理计划");
- expect(html).not.toContain("始终允许");
- expect(html).not.toContain("拒绝");
- });
- it("localizes GLM project-scoped generic permission options", () => {
- const html = renderPermissionDialog(
- {
- type: "permission_request",
- taskId: "task-1",
- traceId: "trace-1",
- requestId: "request-1",
- description: "Run shell command",
- kind: "execute",
- title: "Run shell command",
- options: [
- {
- optionId: "allow_project",
- kind: "allow_always",
- name: "Always allow in this project",
- },
- ],
- raw: {
- rawInput: {
- command: "printf '102384' >> test.md",
- },
- },
- },
- "glm",
- );
- expect(html).toContain("始终允许此命令");
- expect(html).toContain("后续相同命令不再询问");
- expect(html).not.toContain("Always allow in this project");
- });
- it("keeps non-Codex session-scoped permission option names provider-native", () => {
- const html = renderPermissionDialog(
- {
- type: "permission_request",
- taskId: "task-1",
- traceId: "trace-1",
- requestId: "request-1",
- description: "Run shell command",
- kind: "execute",
- title: "Run shell command",
- options: [
- {
- optionId: "allow_for_session",
- kind: "allow_always",
- name: "Allow for Session",
- },
- ],
- raw: {
- rawInput: {
- command: "printf '102384' >> test.md",
- },
- },
- },
- "claude",
- );
- expect(html).toContain("Allow for Session");
- expect(html).not.toContain("允许本会话");
- });
- it("renders file change previews with file display for add operations", () => {
- const html = renderPermissionDialog({
- type: "permission_request",
- taskId: "task-1",
- traceId: "trace-1",
- requestId: "request-1",
- description: "Apply patch",
- kind: "apply_patch",
- title: "Apply patch",
- options: [
- {
- optionId: "allow",
- kind: "allow_once",
- name: "允许",
- },
- ],
- raw: {
- changes: {
- "/Users/dev/ZCodeProject/demo/README.md": {
- type: "add",
- content: "\n",
- },
- },
- },
- });
- expect(html).toContain("README.md");
- expect(html).toContain("等待确认");
- expect(html).not.toContain("/Users/dev/ZCodeProject/demo/");
- });
- it("renders ZCode protocol Write input as an existing file preview", () => {
- const html = renderPermissionDialog({
- type: "permission_request",
- taskId: "task-1",
- traceId: "trace-1",
- requestId: "request-1",
- description: "Tool has side effects and requires approval",
- kind: "Write",
- title: "Write",
- options: [
- {
- optionId: "allow",
- kind: "allow_once",
- name: "允许",
- },
- ],
- raw: {
- requestId: "request-1",
- toolName: "Write",
- input: {
- file_path: "/Users/dev/ZCodeProject/demo/quicksort.js",
- content: "export function quicksort(items) {\n return items;\n}\n",
- },
- },
- });
- expect(html).toContain("quicksort.js");
- expect(html).toContain("等待确认");
- expect(html).toContain("+3");
- expect(html).not.toContain("toolName");
- expect(html).not.toContain("file_path");
- });
- it("renders ZCode protocol Edit input as an existing file preview", () => {
- const html = renderPermissionDialog({
- type: "permission_request",
- taskId: "task-1",
- traceId: "trace-1",
- requestId: "request-1",
- description: "Tool has side effects and requires approval",
- kind: "Edit",
- title: "Edit",
- options: [
- {
- optionId: "allow",
- kind: "allow_once",
- name: "允许",
- },
- ],
- raw: {
- requestId: "request-1",
- toolName: "Edit",
- input: {
- file_path: "/Users/dev/ZCodeProject/demo/quicksort.js",
- old_string: "平均时间复杂度 O(n log n)",
- new_string: "平均时间复杂度 O(n log n),最坏 O(n^2)",
- },
- },
- });
- expect(html).toContain("quicksort.js");
- expect(html).toContain("等待确认");
- expect(html).toContain("+1");
- expect(html).toContain("-1");
- expect(html).not.toContain("old_string");
- expect(html).not.toContain("new_string");
- });
- it("renders grouped file changes for multiple updates", () => {
- const html = renderPermissionDialog({
- type: "permission_request",
- taskId: "task-1",
- traceId: "trace-1",
- requestId: "request-1",
- description: "Apply patch",
- kind: "apply_patch",
- title: "Apply patch",
- options: [
- {
- optionId: "allow",
- kind: "allow_once",
- name: "允许",
- },
- ],
- raw: {
- changes: {
- "/Users/dev/ZCodeProject/demo/index.html": {
- type: "update",
- content: "<html></html>",
- },
- "/Users/dev/ZCodeProject/demo/styles.css": {
- type: "update",
- content: "body {}",
- },
- "/Users/dev/ZCodeProject/demo/script.js": {
- type: "update",
- content: "console.log('ok')",
- },
- },
- },
- });
- expect(html).toContain("等待确认");
- expect(html).toContain("index.html");
- expect(html).toContain("styles.css");
- expect(html).toContain("script.js");
- expect(html).not.toContain("/Users/dev/ZCodeProject/demo/");
- });
- it("不再承载聊天底部主列宽度和 summary 偏移", () => {
- const html = renderPermissionDialog({
- type: "permission_request",
- taskId: "task-1",
- traceId: "trace-1",
- requestId: "request-1",
- description: "Run shell command",
- kind: "execute",
- title: "Run shell command",
- options: [
- {
- optionId: "allow",
- kind: "allow_once",
- name: "允许",
- },
- ],
- raw: {
- rawInput: {
- command: "printf ok",
- },
- },
- });
- expect(html).toContain("Run shell command");
- expect(html).toContain("等待确认");
- expect(html).not.toContain("执行中");
- expect(html).not.toContain("translate-x");
- expect(html).not.toContain("max-w-3xl");
- expect(html).not.toContain("max-w-2xl");
- });
- it("renders Bash input description as the permission reason instead of a running state", () => {
- const html = renderPermissionDialog({
- type: "permission_request",
- taskId: "task-1",
- traceId: "trace-1",
- requestId: "request-bash-description",
- description: "High risk tools require explicit approval",
- kind: "Bash",
- title: "Bash",
- options: [
- {
- optionId: "allow",
- kind: "allow_once",
- name: "允许",
- },
- ],
- raw: {
- requestId: "request-bash-description",
- reason: "High risk tools require explicit approval",
- toolName: "Bash",
- input: {
- description: "Check package.json scripts",
- command: 'cat /Users/dev/test/z-m/package.json 2>/dev/null || echo "No package.json"',
- },
- },
- });
- expect(html).toContain("Check package.json scripts");
- expect(html).toContain("等待确认");
- expect(html).toContain("cat /Users/dev/test/z-m/package.json");
- expect(html).not.toContain("High risk tools require explicit approval");
- expect(html).not.toContain("执行中");
- });
- it("hides the generic high-risk policy reason when no tool description exists", () => {
- const html = renderPermissionDialog({
- type: "permission_request",
- taskId: "task-1",
- traceId: "trace-1",
- requestId: "request-high-risk-policy-reason",
- description: "High risk tools require explicit approval",
- kind: "Bash",
- title: "Bash",
- options: [
- {
- optionId: "allow",
- kind: "allow_once",
- name: "允许",
- },
- ],
- raw: {
- requestId: "request-high-risk-policy-reason",
- reason: "High risk tools require explicit approval",
- riskLevel: "high",
- toolName: "Bash",
- input: {
- command: "rm -rf ./generated",
- },
- },
- });
- expect(html).toContain("等待确认");
- expect(html).toContain("rm -rf ./generated");
- expect(html).not.toContain("High risk tools require explicit approval");
- });
- it("renders WebFetch permission requests as a URL summary instead of fallback JSON", () => {
- const url =
- "https://www.zhihu.com/search?q=%E6%99%BA%E8%B0%B1AI%20Agent%20%E9%9D%A2%E8%AF%95%E9%A2%98";
- const html = renderPermissionDialog({
- type: "permission_request",
- taskId: "task-1",
- traceId: "trace-1",
- requestId: "perm-webfetch",
- description: "Tool has side effects and requires approval",
- kind: "WebFetch",
- title: "WebFetch",
- options: [
- {
- optionId: "allow",
- kind: "allow_once",
- name: "允许",
- },
- {
- optionId: "deny",
- kind: "deny",
- name: "拒绝",
- },
- ],
- raw: {
- requestId: "perm-webfetch",
- toolName: "WebFetch",
- input: {
- url,
- prompt: "List all AI Agent / LLM application development interview questions mentioned",
- },
- },
- });
- expect(html).toContain(url);
- expect(html).toContain("等待确认");
- expect(html).not.toContain("Tool has side effects and requires approval");
- expect(html).not.toContain("List all AI Agent");
- expect(html).not.toContain(""toolId"");
- expect(html.match(/WebFetch/g)?.length ?? 0).toBeLessThanOrEqual(1);
- });
- it("renders MCP permission requests without the generic policy reason", () => {
- const toolName = "mcp__ios-simulator__ios_preflight";
- const reason = "Tool has side effects and requires approval";
- const html = renderPermissionDialog({
- type: "permission_request",
- taskId: "task-1",
- traceId: "trace-1",
- requestId: "perm-mcp",
- description: reason,
- kind: toolName,
- title: toolName,
- options: [
- {
- optionId: "allow",
- kind: "allow_once",
- name: "允许",
- },
- {
- optionId: "deny",
- kind: "deny",
- name: "拒绝",
- },
- ],
- raw: {
- requestId: "perm-mcp",
- toolCallId: "call-mcp",
- toolName,
- reason,
- riskLevel: "medium",
- input: {},
- },
- });
- expect(html.match(new RegExp(toolName, "g"))?.length ?? 0).toBe(1);
- expect(html).not.toContain(reason);
- expect(html).not.toContain(""reason"");
- expect(html).not.toContain(""toolCallId"");
- });
- it("keeps a specific MCP permission reason visible", () => {
- const toolName = "mcp__ios-simulator__ios_preflight";
- const reason = "The simulator must be booted before installing the app";
- const html = renderPermissionDialog({
- type: "permission_request",
- taskId: "task-1",
- traceId: "trace-1",
- requestId: "perm-mcp-specific-reason",
- description: reason,
- kind: toolName,
- title: toolName,
- options: [
- {
- optionId: "allow",
- kind: "allow_once",
- name: "允许",
- },
- {
- optionId: "deny",
- kind: "deny",
- name: "拒绝",
- },
- ],
- raw: {
- requestId: "perm-mcp-specific-reason",
- toolCallId: "call-mcp-specific-reason",
- toolName,
- reason,
- riskLevel: "medium",
- input: {},
- },
- });
- expect(html).toContain(reason);
- });
- it("keeps CUA macOS permission actions out of tool approval dialogs", () => {
- const toolName = "mcp__zcode-cua__request_access";
- const html = renderPermissionDialog(
- {
- type: "permission_request",
- taskId: "task-1",
- traceId: "trace-1",
- requestId: "perm-cua",
- description: "Tool has side effects and requires approval",
- kind: toolName,
- title: toolName,
- options: [
- {
- optionId: "allow",
- kind: "allow_once",
- name: "允许",
- },
- {
- optionId: "deny",
- kind: "deny",
- name: "拒绝",
- },
- ],
- raw: {
- requestId: "perm-cua",
- toolName,
- input: {
- permissions: ["accessibility"],
- },
- },
- },
- undefined,
- );
- expect(html).not.toContain("打开辅助功能设置");
- expect(html).not.toContain("ZCode Computer Use.app");
- expect(html).toContain("允许");
- });
- it("does not offer the Computer Use Helper Accessibility action for unrelated MCP permission requests", () => {
- const toolName = "mcp__ios-simulator__ios_preflight";
- const html = renderPermissionDialog(
- {
- type: "permission_request",
- taskId: "task-1",
- traceId: "trace-1",
- requestId: "perm-mcp",
- description: "Tool has side effects and requires approval",
- kind: toolName,
- title: toolName,
- options: [
- {
- optionId: "allow",
- kind: "allow_once",
- name: "允许",
- },
- {
- optionId: "deny",
- kind: "deny",
- name: "拒绝",
- },
- ],
- raw: {
- requestId: "perm-mcp",
- toolName,
- input: {},
- },
- },
- undefined,
- );
- expect(html).not.toContain("打开辅助功能设置");
- expect(html).not.toContain("ZCode Computer Use.app");
- });
- it("does not offer the Computer Use Helper Accessibility action for ordinary zcode-cua tool requests", () => {
- const toolName = "mcp__zcode-cua__left_click";
- const html = renderPermissionDialog(
- {
- type: "permission_request",
- taskId: "task-1",
- traceId: "trace-1",
- requestId: "perm-cua-click",
- description: "Tool has side effects and requires approval",
- kind: toolName,
- title: toolName,
- options: [
- {
- optionId: "allow",
- kind: "allow_once",
- name: "允许",
- },
- {
- optionId: "deny",
- kind: "deny",
- name: "拒绝",
- },
- ],
- raw: {
- requestId: "perm-cua-click",
- toolName,
- input: {
- target: { type: "coordinate", x: 10, y: 10, space: "screen" },
- },
- },
- },
- undefined,
- );
- expect(html).not.toContain("打开辅助功能设置");
- expect(html).not.toContain("ZCode Computer Use.app");
- });
- });
|