conversation-session-tool-group-reasoning-visibility-boundary.test.ts 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. import { listToolCallBlocks } from "#e2e/helpers/conversation-session-tool";
  2. import { restartIntoWorkspacePreservingProfile } from "#e2e/helpers/model-provider-restart";
  3. import { rm } from "node:fs/promises";
  4. import { clearAppData, seedSettings } from "../helpers/desktop-app.js";
  5. import {
  6. listConversationToolGroups,
  7. toggleLatestConversationToolGroup,
  8. } from "../helpers/conversation-session-tool-groups.js";
  9. import { ensureToolCrossProductFullAccessMode } from "../helpers/conversation-session-tool-cross-product.js";
  10. import { resolveE2ERuntimePath, resolveE2EToolPath } from "../helpers/e2e-runtime-paths.js";
  11. import {
  12. E2E_REPLY_TOKEN,
  13. getV4PaneSnapshot,
  14. prepareV4ConversationE2E,
  15. selectV4TaskById,
  16. sendV4Prompt,
  17. switchV4Mode,
  18. waitForV4AssistantMessageContaining,
  19. waitForV4Pane,
  20. } from "../helpers/v4-conversation.js";
  21. import { expandAssistantHistoriesWithContent } from "../helpers/conversation-session-tool-diagnostics.js";
  22. const CASE_NAME = "conversation-session-tool-group-reasoning-visibility-boundary";
  23. const CASE_MARKER = "E2E_TOOL_GROUP_REASONING_VISIBILITY_BOUNDARY";
  24. const RUNTIME_ROOT = resolveE2ERuntimePath(CASE_NAME);
  25. const FILE_PATH = resolveE2EToolPath(CASE_NAME, "reasoning.ts");
  26. describe("TGE04 reasoning visibility grouping boundary", () => {
  27. before(async function () {
  28. this.timeout(150000);
  29. await seedSettings({
  30. messageStreamShowReasoning: false,
  31. messageStreamShowReasoningMigrationInitialized: true,
  32. toolGroupingChangesEnabled: true,
  33. });
  34. await prepareV4ConversationE2E();
  35. await switchV4Mode("yolo");
  36. });
  37. afterEach(async () => {
  38. await rm(RUNTIME_ROOT, { recursive: true, force: true });
  39. });
  40. after(async () => {
  41. await browser.electron.restoreAllMocks();
  42. await clearAppData();
  43. });
  44. it("隐藏 reasoning 时合并,显示后按可见 reasoning 拆分", async function () {
  45. this.timeout(240000);
  46. await ensureToolCrossProductFullAccessMode();
  47. await sendV4Prompt(
  48. [
  49. `${CASE_MARKER}: Think briefly before every numbered step, then follow all steps in order.`,
  50. `1. Bash: node -e "console.log('TGE04_EXEC_A')"`,
  51. `2. Bash: node -e "console.log('TGE04_EXEC_B')"`,
  52. `3. Write ${FILE_PATH} with exactly "export const reasoning = 'a';\\n".`,
  53. `4. Edit ${FILE_PATH}, replacing "'a'" with "'b'".`,
  54. `5. Reply with exactly "${E2E_REPLY_TOKEN}" and no other text.`,
  55. ].join(" "),
  56. );
  57. await waitForV4AssistantMessageContaining(E2E_REPLY_TOKEN, 150000);
  58. await waitForV4Pane(
  59. (snapshot) => !snapshot.canStop,
  60. "reasoning boundary 工具轮没有结束",
  61. 150000,
  62. );
  63. await expandAssistantHistoriesWithContent();
  64. const hiddenGroups = await listConversationToolGroups();
  65. expect(hiddenGroups.filter((group) => group.toolName === "ExecuteGroup")).toHaveLength(1);
  66. expect(hiddenGroups.filter((group) => group.toolName === "ChangesGroup")).toHaveLength(1);
  67. await toggleLatestConversationToolGroup("ExecuteGroup", true);
  68. await toggleLatestConversationToolGroup("ChangesGroup", true);
  69. const expandedHiddenGroups = await listConversationToolGroups();
  70. expect(
  71. expandedHiddenGroups.find((group) => group.toolName === "ExecuteGroup")?.childCount,
  72. ).toBe(2);
  73. expect(
  74. expandedHiddenGroups.find((group) => group.toolName === "ChangesGroup")?.childCount,
  75. ).toBe(2);
  76. const sessionId = (await getV4PaneSnapshot()).sessionId;
  77. if (!sessionId || sessionId === "draft") throw new Error("TGE04 缺少可恢复 sessionId");
  78. await seedSettings({ messageStreamShowReasoning: true });
  79. await reloadAndRestoreSession(sessionId);
  80. await expandAssistantHistoriesWithContent();
  81. // 可见 reasoning 把每组拆成单工具;当前 singleton 直接显示原始行,不创建空壳父组。
  82. await browser.waitUntil(
  83. async () =>
  84. (await listToolCallBlocks()).filter((block) =>
  85. ["Bash", "Write", "Edit"].includes(block.toolName ?? ""),
  86. ).length === 4,
  87. { timeout: 30000, timeoutMsg: "reasoning 拆分后原始工具行未恢复" },
  88. );
  89. const tools = (await listToolCallBlocks()).filter((block) =>
  90. ["Bash", "Write", "Edit"].includes(block.toolName ?? ""),
  91. );
  92. expect(tools.map((tool) => tool.toolName)).toEqual(["Bash", "Bash", "Write", "Edit"]);
  93. expect(tools.every((tool) => tool.status === "completed")).toBe(true);
  94. expect(await listConversationToolGroups()).toHaveLength(0);
  95. expect(await $$('[data-testid="v4-timeline"] [data-reasoning-label="true"]').length).toBe(4);
  96. });
  97. });
  98. async function reloadAndRestoreSession(sessionId: string) {
  99. // 冷恢复必须保留 Chromium profile;不把临时新 profile 当作用户重启。
  100. await restartIntoWorkspacePreservingProfile();
  101. await selectV4TaskById(sessionId);
  102. await waitForV4Pane(
  103. (snapshot) => snapshot.sessionId === sessionId,
  104. `TGE04 没有恢复 session ${sessionId}`,
  105. 60000,
  106. );
  107. await waitForRestoredSessionStable(sessionId, "TGE04 cold restore 没有稳定显示原会话");
  108. }
  109. async function waitForRestoredSessionStable(sessionId: string, failureMessage: string) {
  110. let stableSince = 0;
  111. await browser.waitUntil(
  112. async () => {
  113. const snapshot = await getV4PaneSnapshot();
  114. const matches =
  115. snapshot.sessionId === sessionId && snapshot.timelineText.includes(E2E_REPLY_TOKEN);
  116. if (!matches) {
  117. stableSince = 0;
  118. return false;
  119. }
  120. stableSince ||= Date.now();
  121. return Date.now() - stableSince >= 1000;
  122. },
  123. { timeout: 60000, timeoutMsg: failureMessage },
  124. );
  125. }