conversation-session-subagent-sidebar-isolation.test.ts 3.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. import { waitForToolCallBlockByToolCallId } from "#e2e/helpers/conversation-session-tool";
  2. import { DatabaseSync } from "node:sqlite";
  3. import { join } from "node:path";
  4. import { TID_TASK_ITEM, TID_V4_SUBAGENT_OPEN_SIDE_PANE, testId } from "@zcode/shared/test-ids";
  5. import { clearAppData, getE2EAppDataPaths } from "#e2e/helpers/desktop-app";
  6. import {
  7. prepareV4ConversationE2E,
  8. sendV4Prompt,
  9. getV4PaneSnapshot,
  10. waitForV4AssistantMessageContaining,
  11. waitForV4Pane,
  12. } from "#e2e/helpers/v4-conversation";
  13. import { restartIntoWorkspacePreservingProfile } from "#e2e/helpers/model-provider-restart";
  14. import { ensureToolCrossProductFullAccessMode } from "#e2e/helpers/conversation-session-tool-cross-product";
  15. const PARENT = "E2E_SUBAGENT_SIDEBAR_PARENT";
  16. const PARENT_DONE = "E2E_SUBAGENT_SIDEBAR_PARENT_DONE";
  17. const CHILD_DONE = "E2E_SUBAGENT_SIDEBAR_CHILD_DONE";
  18. const paths = getE2EAppDataPaths();
  19. describe("子代理冷恢复主列表隔离", () => {
  20. after(async () => {
  21. await browser.electron.restoreAllMocks();
  22. await clearAppData();
  23. });
  24. it("SAT27/SAT28: 真正派发 child 后冷启,详情可读且主列表保持隐藏", async function () {
  25. this.timeout(240000);
  26. await prepareV4ConversationE2E();
  27. await ensureToolCrossProductFullAccessMode();
  28. await sendV4Prompt(
  29. `${PARENT}: launch one general-purpose Agent to reply with E2E_SUBAGENT_SIDEBAR_CHILD_DONE, then report E2E_SUBAGENT_SIDEBAR_PARENT_DONE.`,
  30. );
  31. await waitForV4AssistantMessageContaining(PARENT_DONE, 90000);
  32. await waitForV4Pane((state) => !state.canStop, "父任务未完成", 30000);
  33. const parentId = (await getV4PaneSnapshot()).sessionId;
  34. if (!parentId) throw new Error("missing parent session");
  35. const childId = readChildId(parentId);
  36. await openChild();
  37. await assertChildIsolated(childId);
  38. // 真正重启 CLI 清空 detached publisher;打开历史详情必须恢复原身份。
  39. await restartIntoWorkspacePreservingProfile();
  40. const parent = $(`[data-testid="${testId(TID_TASK_ITEM, parentId)}"]`);
  41. await parent.waitForDisplayed({ timeout: 30000 });
  42. await parent.click();
  43. await waitForV4AssistantMessageContaining(PARENT_DONE, 30000);
  44. await openChild();
  45. await assertChildIsolated(childId);
  46. expect(readChildId(parentId)).toBe(childId);
  47. });
  48. });
  49. function readChildId(parentId: string): string {
  50. const db = new DatabaseSync(join(paths.storageRoot, "cli", "db", "db.sqlite"), {
  51. readOnly: true,
  52. });
  53. try {
  54. const row = db
  55. .prepare("SELECT id FROM session WHERE parent_id = ? AND task_type = 'subagent_child'")
  56. .get(parentId) as { id: string } | undefined;
  57. if (!row) throw new Error("Agent 没有持久化 subagent_child");
  58. return row.id;
  59. } finally {
  60. db.close();
  61. }
  62. }
  63. async function openChild() {
  64. const block = await waitForToolCallBlockByToolCallId("toolu_e2e_subagent_sidebar", 30000);
  65. const action = $(`[data-testid="${block.testId}"]`).$(
  66. `[data-testid^="${TID_V4_SUBAGENT_OPEN_SIDE_PANE}-"]`,
  67. );
  68. await action.waitForDisplayed({ timeout: 30000 });
  69. await action.click();
  70. }
  71. async function assertChildIsolated(childId: string) {
  72. const child = $(`[data-session-id="${childId}"]`);
  73. await child.waitForDisplayed({ timeout: 30000 });
  74. await browser.waitUntil(async () => (await child.getText()).includes(CHILD_DONE), {
  75. timeout: 30000,
  76. timeoutMsg: "child 转录未恢复",
  77. });
  78. expect(await child.$('[contenteditable="true"]').isExisting()).toBe(false);
  79. expect(await $(`[data-testid="${testId(TID_TASK_ITEM, childId)}"]`).isExisting()).toBe(false);
  80. await browser.saveScreenshot(join(paths.storageRoot, "subagent-sidebar-isolation.png"));
  81. }