conversation-session-plugin-reference-subagent.test.ts 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. // PLG16 formal E2E:Plugin 引用的 model-only system reminder 必须把该 Plugin
  2. // 当前 Session 实际加载成功的 canonical Subagent identifier 一并发送给 provider;
  3. // 不得注入 profile 描述、system prompt 或文件路径,也不得把 reminder 显示到时间线。
  4. import { clearAppData } from "#e2e/helpers/desktop-app";
  5. import { waitForUpstreamNetworkCapture } from "#e2e/helpers/upstream-capture";
  6. import {
  7. PLUGIN_INLINE_ID,
  8. PLUGIN_INLINE_SUBAGENT_NAME,
  9. restartPluginLifecycleApp,
  10. seedInlineLifecyclePlugin,
  11. } from "#e2e/helpers/plugin-management-lifecycle";
  12. import {
  13. prepareV4ConversationE2E,
  14. sendV4Prompt,
  15. startNewV4Draft,
  16. waitForV4Pane,
  17. waitForV4TimelineContaining,
  18. } from "#e2e/helpers/v4-conversation";
  19. const PROMPT_MARKER = "E2E_PLUGIN_REFERENCE_SUBAGENT";
  20. const REPLY_MARKER = "PLUGIN_REFERENCE_SUBAGENT_REPLY_OK";
  21. const PLUGIN_REFERENCE_TAG = "<plugin_reference>";
  22. describe("PLG16 Plugin 引用 reminder 包含对应 Subagent", () => {
  23. after(async () => {
  24. await browser.electron.restoreAllMocks();
  25. await clearAppData();
  26. });
  27. it("provider 收到 live canonical Subagent identifier,UI 与 reminder 均不泄漏 profile 内容", async function () {
  28. this.timeout(240_000);
  29. await seedInlineLifecyclePlugin();
  30. await restartPluginLifecycleApp();
  31. await prepareV4ConversationE2E();
  32. await startNewV4Draft();
  33. const prompt =
  34. `${PROMPT_MARKER}: use [@${PLUGIN_INLINE_ID}](plugin://${PLUGIN_INLINE_ID}) ` +
  35. `and reply with exactly ${REPLY_MARKER}.`;
  36. await sendV4Prompt(prompt);
  37. await waitForV4TimelineContaining(REPLY_MARKER, 60_000);
  38. await waitForV4Pane(
  39. (state) => !state.canStop && Boolean(state.sessionId && state.sessionId !== "draft"),
  40. "Plugin Subagent 引用回合没有回到 idle",
  41. 60_000,
  42. );
  43. const capture = await waitForUpstreamNetworkCapture(PROMPT_MARKER);
  44. const reminderMessages = readPluginReminderMessages(capture.requestJson);
  45. expect(reminderMessages).toHaveLength(1);
  46. const reminder = reminderMessages[0]!;
  47. expect(reminder).toContain(PLUGIN_INLINE_ID);
  48. expect(reminder).toContain(`subagents: ["${PLUGIN_INLINE_SUBAGENT_NAME}"]`);
  49. expect(reminder).not.toContain("E2E inline Plugin reviewer profile");
  50. expect(reminder).not.toContain("Review the requested files");
  51. expect(reminder).not.toContain("inline-reviewer.md");
  52. const timelineHasReminder = await browser.execute(
  53. (tag) => (document.body.textContent ?? "").includes(tag),
  54. PLUGIN_REFERENCE_TAG,
  55. );
  56. expect(timelineHasReminder).toBe(false);
  57. });
  58. });
  59. function readPluginReminderMessages(requestJson: unknown): string[] {
  60. if (!requestJson || typeof requestJson !== "object" || Array.isArray(requestJson)) {
  61. throw new Error("Plugin Subagent provider request 不是 JSON object");
  62. }
  63. const messages = (requestJson as { messages?: unknown }).messages;
  64. if (!Array.isArray(messages)) {
  65. throw new Error("Plugin Subagent provider request 缺少 messages 数组");
  66. }
  67. // Provider 会合并相邻 user 文本;其他 reminder 的合法 Subagent catalog 描述
  68. // 不属于 plugin_reference。只检查该块,仍禁止 profile 内容进入插件引用元数据。
  69. return messages.flatMap((message) => {
  70. const content = message?.content;
  71. const texts =
  72. typeof content === "string"
  73. ? [content]
  74. : Array.isArray(content)
  75. ? content.flatMap((block: { type?: string; text?: string }) =>
  76. block.type === "text" && typeof block.text === "string" ? [block.text] : [],
  77. )
  78. : [];
  79. return texts.flatMap((text: string) =>
  80. [...text.matchAll(/<plugin_reference>[\s\S]*?<\/plugin_reference>/g)].map(
  81. (match) => match[0],
  82. ),
  83. );
  84. });
  85. }