conversation-session-tool-error-surface.test.ts 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. import { expandAssistantHistoriesWithContent } from "#e2e/helpers/conversation-session-tool-diagnostics";
  2. import { clearAppData } from "#e2e/helpers/desktop-app";
  3. import {
  4. prepareV4ConversationE2E,
  5. sendV4Prompt,
  6. waitForV4AssistantMessageContaining,
  7. waitForV4ConversationState,
  8. waitForV4ComposerText,
  9. waitForV4UserMessageContaining,
  10. } from "#e2e/helpers/v4-conversation";
  11. import { waitForUpstreamRequest } from "#e2e/helpers/conversation-session-network";
  12. import { waitForFoldedToolCallBlockByToolCallId } from "#e2e/helpers/conversation-session-tool";
  13. import { getToolCallDiagnostics } from "#e2e/helpers/conversation-session-tool-diagnostics";
  14. const PARENT_MARKER = "E2E_TOOL_ERROR_SURFACE_PARENT";
  15. const STALE_CHILD_MARKER = "E2E_TOOL_ERROR_SURFACE_STALE_CHILD";
  16. const HEALTHY_CHILD_MARKER = "E2E_TOOL_ERROR_SURFACE_HEALTHY_CHILD";
  17. const HEALTHY_CHILD_DONE = "E2E_TOOL_ERROR_SURFACE_HEALTHY_OK";
  18. const PARENT_DONE = "E2E_TOOL_ERROR_SURFACE_PARENT_DONE";
  19. const STALE_AGENT_TYPE = "e2e-stale-error-reviewer";
  20. const HEALTHY_AGENT_TYPE = "e2e-healthy-error-reviewer";
  21. const STALE_PROVIDER_ID = "e2e-stale-provider";
  22. const STALE_MODEL_ID = "e2e-stale-model";
  23. const STALE_ERROR_TEXT = `reason=provider-not-found; selection=${STALE_PROVIDER_ID}/${STALE_MODEL_ID}`;
  24. const GENERIC_TURN_ERROR_TEXT = "Turn execution failed";
  25. const STALE_AGENT_TOOL_CALL_ID = "toolu_e2e_tool_error_surface_stale_agent";
  26. const HEALTHY_AGENT_TOOL_CALL_ID = "toolu_e2e_tool_error_surface_healthy_agent";
  27. describe("会话区 toolcall 错误展示 E2E", () => {
  28. after(async () => {
  29. await browser.electron.restoreAllMocks();
  30. await clearAppData();
  31. });
  32. it("Z01: Agent 失败工具卡展示真实 provider 根因且不阻断同轮 sibling Agent", async function () {
  33. this.timeout(180000);
  34. await prepareV4ConversationE2E();
  35. const runId = Date.now();
  36. const marker = `${PARENT_MARKER}_${runId}`;
  37. const prompt = [
  38. `${marker}: launch two Agent tools in the same assistant response.`,
  39. `One must use subagent_type "${STALE_AGENT_TYPE}" for ${STALE_CHILD_MARKER}.`,
  40. `The other must use subagent_type "${HEALTHY_AGENT_TYPE}" for ${HEALTHY_CHILD_MARKER}.`,
  41. `After both tool results return, reply with exactly ${PARENT_DONE}.`,
  42. ].join(" ");
  43. await sendV4Prompt(prompt);
  44. await waitForV4ComposerText("", "tool error surface 首发后输入框没有清空");
  45. await waitForV4UserMessageContaining(marker);
  46. // 最终回复会收起工具历史;先确认回合完成,再由公共 helper 展开历史检查两张卡。
  47. await waitForV4AssistantMessageContaining(PARENT_DONE);
  48. await waitForV4ConversationState(
  49. (snapshot) => snapshot.state === "idle" && snapshot.queueCount === 0,
  50. "tool error surface case 完成后没有回到 idle",
  51. 60000,
  52. );
  53. // 修复原因:最后一轮结束后保持同一组件实例,约 0.3 秒后工具卡才收进工作记录并重挂;
  54. // 通用等待器可能命中收起前的旧卡,悬停随后落在已卸载的状态文字上,tooltip 不出现。
  55. await waitForFoldedToolCallBlockByToolCallId(STALE_AGENT_TOOL_CALL_ID, 60000);
  56. await waitForFoldedToolCallBlockByToolCallId(HEALTHY_AGENT_TOOL_CALL_ID, 60000);
  57. await waitForToolBlockStatus(STALE_AGENT_TOOL_CALL_ID, "failed");
  58. await waitForToolBlockStatus(HEALTHY_AGENT_TOOL_CALL_ID, "completed");
  59. // V4 不写旧 taskMessagesByTaskId;读取真实失败卡的 hover,避免把旧 Store 空数组
  60. // 误判成错误丢失。Registry 在启动前拒绝失效 Provider,根因包含完整模型身份。
  61. // 修复原因:轮次结束后工具卡会收进「已工作」折叠,折叠收起时卡片从 DOM 卸载;先展开再悬停。
  62. await expandAssistantHistoriesWithContent();
  63. const failureStatus = $(`[data-tool-call-id="${STALE_AGENT_TOOL_CALL_ID}"] .cursor-help`);
  64. await failureStatus.waitForDisplayed({ timeout: 15000 });
  65. // Radix 的 role=tooltip 是屏幕阅读器副本;可见内容在 tooltip-content。
  66. const tooltip = $('[data-slot="tooltip-content"]');
  67. await hoverUntilTooltipDisplayed(failureStatus, tooltip);
  68. const errorText = await tooltip.getText();
  69. expect(errorText).toContain(STALE_ERROR_TEXT);
  70. expect(errorText).not.toContain(GENERIC_TURN_ERROR_TEXT);
  71. await waitForUpstreamRequest(
  72. {
  73. excludes: [GENERIC_TURN_ERROR_TEXT],
  74. includes: [
  75. marker,
  76. STALE_AGENT_TOOL_CALL_ID,
  77. HEALTHY_AGENT_TOOL_CALL_ID,
  78. STALE_ERROR_TEXT,
  79. HEALTHY_CHILD_DONE,
  80. ],
  81. },
  82. "父 continuation 没有同时收到真实失败 tool_result 和 sibling Agent 成功结果",
  83. 60000,
  84. );
  85. });
  86. });
  87. async function waitForToolBlockStatus(toolCallId: string, status: string, timeout = 60000) {
  88. let latestStatus: string | null = null;
  89. await browser.waitUntil(
  90. async () => {
  91. const diagnostics = await getToolCallDiagnostics({
  92. type: "toolCallId",
  93. value: toolCallId,
  94. });
  95. latestStatus = diagnostics.matchedBlock?.status ?? null;
  96. return latestStatus === status;
  97. },
  98. {
  99. timeout,
  100. timeoutMsg: `toolCallId=${toolCallId} 没有进入 ${status}; latestStatus=${latestStatus}`,
  101. },
  102. );
  103. }
  104. /**
  105. * 悬停状态文字,直到 tooltip 可见。
  106. * 修复原因:工具卡收进工作记录后,展开的工作记录内容约 250ms 内仍在滚动(scrollTop 动画到 0);
  107. * Radix Tooltip 在祖先滚动时关闭(运行时记录:60ms delayed-open,72ms scroll,77ms closed)。
  108. * 指针停在原地不会再触发打开,Radix 要先收到 pointerleave 才重新响应 pointermove。
  109. * 每轮先把指针移到状态文字左侧 3px(与失败图标之间的间隙,不落在其他 tooltip 触发器上),
  110. * 再移回状态文字,等滚动停下后的那次悬停打开 tooltip。
  111. */
  112. async function hoverUntilTooltipDisplayed(
  113. trigger: ReturnType<typeof $>,
  114. tooltip: ReturnType<typeof $>,
  115. timeout = 15000,
  116. ) {
  117. await browser.waitUntil(
  118. async () => {
  119. const element = await trigger;
  120. const { width } = await element.getSize();
  121. await browser
  122. .action("pointer", { parameters: { pointerType: "mouse" } })
  123. .move({ origin: element, x: -(Math.floor(width / 2) + 3), y: 0 })
  124. .perform();
  125. await element.moveTo();
  126. return tooltip
  127. .waitForDisplayed({ timeout: 1000 })
  128. .then(() => true)
  129. .catch(() => false);
  130. },
  131. { timeout, interval: 0, timeoutMsg: "失败状态文字悬停后 tooltip 没有显示" },
  132. );
  133. }