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

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