conversation-session-permission-full-access.test.ts 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. // PA158:真实审批、风险勾选、混合 Plan 队列及撤回编辑。
  2. import { mkdir, readFile, rm } from "node:fs/promises";
  3. import { join } from "node:path";
  4. import { clearAppData } from "../helpers/desktop-app.js";
  5. import { resolveE2ERuntimePath } from "../helpers/e2e-runtime-paths.js";
  6. import {
  7. clickV4QueueItemEdit,
  8. getV4ConfigProjection,
  9. getV4ModelConfig,
  10. getV4QueueItems,
  11. prepareV4ConversationE2E,
  12. sendV4Prompt,
  13. setV4ComposerText,
  14. waitForV4ComposerText,
  15. switchV4Mode,
  16. waitForV4PermissionDialog,
  17. waitForV4QueueCount,
  18. waitForV4TimelineContaining,
  19. } from "../helpers/v4-conversation.js";
  20. const CASE = "conversation-session-permission-full-access";
  21. const DIRECTORY = resolveE2ERuntimePath(CASE);
  22. describe("PA158 审批完全访问", () => {
  23. before(async () => {
  24. await mkdir(DIRECTORY, { recursive: true });
  25. });
  26. after(async () => {
  27. await browser.electron.restoreAllMocks();
  28. await clearAppData();
  29. await rm(DIRECTORY, { recursive: true, force: true });
  30. });
  31. it("原轮继续,运行中队列分别保留 Plan,撤回编辑权限为 yolo", async () => {
  32. // 新隔离 HOME 会先进入职业引导,按真实 UI 完成准备,不能伪造业务快照。
  33. await browser.waitUntil(
  34. async () =>
  35. browser.execute(() =>
  36. Boolean(
  37. document.querySelector(
  38. '[data-testid="onboarding-page"],[data-testid="login-use-api-key-button"],[data-testid^="v4-session-pane-"]',
  39. ),
  40. ),
  41. ),
  42. { timeout: 30000 },
  43. );
  44. const onboarding = await $('[data-testid="onboarding-page"]');
  45. if (await onboarding.isExisting()) {
  46. for (let step = 0; step < 3; step += 1) {
  47. await $(
  48. '//main[@data-testid="onboarding-page"]//button[normalize-space()="Skip" or normalize-space()="跳过"]',
  49. ).click();
  50. }
  51. await onboarding.waitForExist({ reverse: true });
  52. }
  53. await prepareV4ConversationE2E();
  54. await switchV4Mode("build");
  55. await sendV4Prompt("E2E_PA158_MAIN 执行需要确认的写文件操作");
  56. await waitForV4TimelineContaining("E2E_PA158_RUNNING");
  57. await switchV4Mode("plan");
  58. await sendV4Prompt("E2E_PA158_QUEUE_PLAN");
  59. await waitForV4QueueCount(1);
  60. await $('[data-testid="v4-composer-plan-marker"] button').click();
  61. // 菜单已隐藏 edit,旧步骤会在授权前超时;用可选的 guarded 保留混合权限和 Plan 场景。
  62. await switchV4Mode("guarded");
  63. expect(await getV4ConfigProjection()).toMatchObject({ mode: "guarded", planEnabled: false });
  64. await sendV4Prompt("E2E_PA158_QUEUE_GUARDED");
  65. await waitForV4QueueCount(2);
  66. const queue = await getV4QueueItems();
  67. await switchV4Mode("plan");
  68. await waitForV4PermissionDialog();
  69. const fullAccess = await $(
  70. 'button[role="option"][aria-label="完全访问"],button[role="option"][aria-label="Full access"]',
  71. );
  72. await fullAccess.waitForDisplayed();
  73. const beforeConfirmation = await getV4ModelConfig();
  74. const assertApprovalStillPending = async () => {
  75. expect(await fullAccess.isDisplayed()).toBe(true);
  76. expect(await getV4ModelConfig()).toEqual(beforeConfirmation);
  77. expect(await getV4ConfigProjection()).toMatchObject({
  78. mode: "guarded",
  79. planEnabled: true,
  80. });
  81. expect(await getV4QueueItems()).toEqual(queue);
  82. await expect(readFile(join(DIRECTORY, "output.txt"), "utf8")).rejects.toMatchObject({
  83. code: "ENOENT",
  84. });
  85. };
  86. if (process.env.ZCODE_E2E_ARTIFACT_DIR) {
  87. await browser.saveScreenshot(
  88. join(process.env.ZCODE_E2E_ARTIFACT_DIR, "permission-full-access.png"),
  89. );
  90. }
  91. await fullAccess.click();
  92. await $('[data-testid="yolo-confirmation-dialog"]').waitForDisplayed();
  93. expect(await $('[data-testid="yolo-confirmation-confirm"]').isEnabled()).toBe(false);
  94. await $('[data-testid="yolo-confirmation-risk"]').click();
  95. await assertApprovalStillPending();
  96. await $('[data-testid="yolo-confirmation-cancel"]').click();
  97. await $('[data-testid="yolo-confirmation-dialog"]').waitForDisplayed({ reverse: true });
  98. await assertApprovalStillPending();
  99. await fullAccess.click();
  100. await $('[data-testid="yolo-confirmation-dialog"]').waitForDisplayed();
  101. expect(await $('[data-testid="yolo-confirmation-confirm"]').isEnabled()).toBe(false);
  102. await $('[data-testid="yolo-confirmation-risk"]').click();
  103. await assertApprovalStillPending();
  104. await $('[data-testid="yolo-confirmation-confirm"]').click();
  105. await waitForV4TimelineContaining("E2E_PA158_DONE");
  106. expect(await readFile(resolveE2ERuntimePath(CASE, "output.txt"), "utf8")).toBe(
  107. "E2E_PA158_TOOL_RESULT\n",
  108. );
  109. expect(await getV4QueueItems()).toEqual(queue);
  110. expect(await getV4ConfigProjection()).toMatchObject({ mode: "yolo", planEnabled: true });
  111. await clickV4QueueItemEdit(queue[0]!.queueItemId);
  112. await waitForV4QueueCount(1);
  113. await waitForV4ComposerText("E2E_PA158_QUEUE_PLAN", "第一项撤回草稿未恢复");
  114. expect(await getV4ConfigProjection()).toMatchObject({ mode: "yolo", planEnabled: true });
  115. await setV4ComposerText("");
  116. await clickV4QueueItemEdit(queue[1]!.queueItemId);
  117. await waitForV4QueueCount(0);
  118. await waitForV4ComposerText("E2E_PA158_QUEUE_GUARDED", "第二项撤回草稿未恢复");
  119. expect(await getV4ConfigProjection()).toMatchObject({ mode: "yolo", planEnabled: false });
  120. });
  121. });