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

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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 "../helpers/desktop-app.js";
  5. import { waitForUpstreamNetworkCapture } from "../helpers/upstream-capture.js";
  6. import {
  7. PLUGIN_INLINE_ID,
  8. PLUGIN_INLINE_SUBAGENT_NAME,
  9. restartPluginLifecycleApp,
  10. seedInlineLifecyclePlugin,
  11. } from "../helpers/plugin-management-lifecycle.js";
  12. import {
  13. prepareV4ConversationE2E,
  14. sendV4Prompt,
  15. startNewV4Draft,
  16. waitForV4Pane,
  17. waitForV4TimelineContaining,
  18. } from "../helpers/v4-conversation.js";
  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) =>
  40. !state.canStop &&
  41. Boolean(state.sessionId && state.sessionId !== "draft"),
  42. "Plugin Subagent 引用回合没有回到 idle",
  43. 60_000,
  44. );
  45. const capture = await waitForUpstreamNetworkCapture(PROMPT_MARKER);
  46. const reminderMessages = readPluginReminderMessages(capture.requestJson);
  47. expect(reminderMessages).toHaveLength(1);
  48. const reminder = JSON.stringify(reminderMessages[0]);
  49. expect(reminder).toContain(PLUGIN_INLINE_ID);
  50. expect(reminder).toContain(
  51. `subagents: [\\"${PLUGIN_INLINE_SUBAGENT_NAME}\\"]`,
  52. );
  53. expect(reminder).not.toContain("E2E inline Plugin reviewer profile");
  54. expect(reminder).not.toContain("Review the requested files");
  55. expect(reminder).not.toContain("inline-reviewer.md");
  56. const timelineHasReminder = await browser.execute(
  57. (tag) => (document.body.textContent ?? "").includes(tag),
  58. PLUGIN_REFERENCE_TAG,
  59. );
  60. expect(timelineHasReminder).toBe(false);
  61. });
  62. });
  63. function readPluginReminderMessages(requestJson: unknown): unknown[] {
  64. if (
  65. !requestJson ||
  66. typeof requestJson !== "object" ||
  67. Array.isArray(requestJson)
  68. ) {
  69. throw new Error("Plugin Subagent provider request 不是 JSON object");
  70. }
  71. const messages = (requestJson as { messages?: unknown }).messages;
  72. if (!Array.isArray(messages)) {
  73. throw new Error("Plugin Subagent provider request 缺少 messages 数组");
  74. }
  75. return messages.filter((message) =>
  76. JSON.stringify(message).includes(PLUGIN_REFERENCE_TAG),
  77. );
  78. }