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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. import { clearAppData } from "../helpers/desktop-app.js";
  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 { waitForToolCallBlockByToolCallId } from "#e2e/helpers/conversation-session-tool";
  12. import { getToolCallDiagnostics } from "../helpers/conversation-session-tool-diagnostics.js";
  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. await waitForToolCallBlockByToolCallId(STALE_AGENT_TOOL_CALL_ID, 60000);
  53. await waitForToolCallBlockByToolCallId(HEALTHY_AGENT_TOOL_CALL_ID, 60000);
  54. await waitForToolBlockStatus(STALE_AGENT_TOOL_CALL_ID, "failed");
  55. await waitForToolBlockStatus(HEALTHY_AGENT_TOOL_CALL_ID, "completed");
  56. // V4 不写旧 taskMessagesByTaskId;读取真实失败卡的 hover,避免把旧 Store 空数组
  57. // 误判成错误丢失。Registry 在启动前拒绝失效 Provider,根因包含完整模型身份。
  58. const failureStatus = $(`[data-tool-call-id="${STALE_AGENT_TOOL_CALL_ID}"] .cursor-help`);
  59. await failureStatus.waitForDisplayed({ timeout: 15000 });
  60. await failureStatus.moveTo();
  61. // Radix 的 role=tooltip 是屏幕阅读器副本;可见内容在 tooltip-content。
  62. const tooltip = $('[data-slot="tooltip-content"]');
  63. await tooltip.waitForDisplayed({ timeout: 15000 });
  64. const errorText = await tooltip.getText();
  65. expect(errorText).toContain(STALE_ERROR_TEXT);
  66. expect(errorText).not.toContain(GENERIC_TURN_ERROR_TEXT);
  67. await waitForUpstreamRequest(
  68. {
  69. excludes: [GENERIC_TURN_ERROR_TEXT],
  70. includes: [
  71. marker,
  72. STALE_AGENT_TOOL_CALL_ID,
  73. HEALTHY_AGENT_TOOL_CALL_ID,
  74. STALE_ERROR_TEXT,
  75. HEALTHY_CHILD_DONE,
  76. ],
  77. },
  78. "父 continuation 没有同时收到真实失败 tool_result 和 sibling Agent 成功结果",
  79. 60000,
  80. );
  81. });
  82. });
  83. async function waitForToolBlockStatus(toolCallId: string, status: string, timeout = 60000) {
  84. let latestStatus: string | null = null;
  85. await browser.waitUntil(
  86. async () => {
  87. const diagnostics = await getToolCallDiagnostics({
  88. type: "toolCallId",
  89. value: toolCallId,
  90. });
  91. latestStatus = diagnostics.matchedBlock?.status ?? null;
  92. return latestStatus === status;
  93. },
  94. {
  95. timeout,
  96. timeoutMsg: `toolCallId=${toolCallId} 没有进入 ${status}; latestStatus=${latestStatus}`,
  97. },
  98. );
  99. }