conversation-session-plugin-mcp-skill-disabled.test.ts 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. // 状态 C:插件 MCP skill 已安装但被禁用。
  2. // 证明:把 e2e-plugin-mcp-ping 导入到 installed_plugins.json 后再通过
  3. // config.json#plugins.enabledPlugins[id]=false 关闭,agent 不会把
  4. // `mcp__plugin_e2e-plugin-mcp-ping_ping__ping` 注册到模型请求 tools 数组,模型也调不到它。
  5. // 软证据:chat 端没有任何该工具的 tool-call block(normal text 轮次)。
  6. // wdio 启动前已在 <E2E_HOME>/.zcode/cli/plugins/installed_plugins.json 写入带 installPath
  7. // 的记录,并把 config.json#plugins.enabledPlugins[id] 显式置为 false。
  8. import { clearAppData } from "#e2e/helpers/desktop-app";
  9. import {
  10. E2E_REPLY_TOKEN,
  11. prepareV4ConversationE2E,
  12. sendV4Prompt,
  13. startNewV4Draft,
  14. waitForV4AssistantMessageContaining,
  15. waitForV4ConversationState,
  16. waitForV4ComposerText,
  17. waitForV4UserMessageContaining,
  18. } from "#e2e/helpers/v4-conversation";
  19. import { getToolCallBlockByToolName } from "#e2e/helpers/conversation-session-tool";
  20. import { waitForUpstreamRequestContaining } from "#e2e/helpers/conversation-session-network";
  21. import {
  22. PLUGIN_MCP_TOOL_NAME,
  23. captureArtifactAdvertisesToolName,
  24. findUpstreamRequestContaining,
  25. } from "#e2e/helpers/plugin-mcp-skill";
  26. const DISABLED_TIMEOUT_MS = 180000;
  27. describe("会话区 插件 MCP Skill 生命周期 E2E / 已安装但禁用", () => {
  28. after(async () => {
  29. await browser.electron.restoreAllMocks();
  30. await clearAppData();
  31. });
  32. it("plugin 已安装但禁用时:请求 tools 数组不含 mcp__plugin_e2e-plugin-mcp-ping_ping__ping,chat 也不出现该工具 block", async function () {
  33. this.timeout(DISABLED_TIMEOUT_MS);
  34. await prepareV4ConversationE2E();
  35. await startNewV4Draft();
  36. const runId = Date.now();
  37. const marker = `E2E_PLUGIN_MCP_PING_DISABLED_${runId}`;
  38. const prompt = `${marker}: Reply with exactly "${E2E_REPLY_TOKEN}" and no other text.`;
  39. await sendV4Prompt(prompt);
  40. await waitForV4ComposerText("", "已禁用 首发后输入框没有清空");
  41. await waitForV4UserMessageContaining(prompt);
  42. await waitForUpstreamRequestContaining(marker, 60000);
  43. const requestRecord = await findUpstreamRequestContaining(marker, 60000);
  44. expect(requestRecord).not.toBeNull();
  45. if (!requestRecord) return;
  46. // 强证据:模型请求的 tools 数组里不能有 plugin MCP 工具。
  47. expect(captureArtifactAdvertisesToolName(requestRecord.requestJson, PLUGIN_MCP_TOOL_NAME)).toBe(
  48. false,
  49. );
  50. // 软证据:chat 端没有任何该工具的 tool-call block(normal text 轮次)。
  51. const block = await getToolCallBlockByToolName(PLUGIN_MCP_TOOL_NAME);
  52. expect(block).toBeNull();
  53. await waitForV4AssistantMessageContaining(E2E_REPLY_TOKEN);
  54. await waitForV4ConversationState(
  55. (snapshot) => snapshot.state === "idle" && snapshot.queueCount === 0,
  56. "已禁用 完成后会话没有回到 idle",
  57. 90000,
  58. );
  59. });
  60. });